Can't run code once upgrading from to

Jul 31, 2016 at 7:17 PM
I've moved to the recent package.... and it's not working very well for me.
My guessed culprit is the conditions are not by default embedded into CDATA which causes to my patches to throw an exception on parsing the Xdocument while called from Compiler.WixSourceGenerated += WixSharpPatches since this is not conformed to XML format.

Any knows how to overcome this problem or encountered a similar issue?
I've recently see ToCdata method but how this could be used in this context.

Any advice is welcome.

Aug 1, 2016 at 12:47 PM
Could you please provide a simple test project that demonstrates the problem.
Thank you
Aug 1, 2016 at 2:08 PM
I will try, though the project is big so I can take some time.

In the meantime, let's see if you can help me with what I wrote above.

Why CDATA has been removed from conditions by default? The conditions can have values that may interfere with XML, and therefore not being properly parsed while using methods for XDocument.

It looks like for example, that document.Root.Select("Product") returns a value, but can't reach: document.Root.Select("Product").Element("InstallExecuteSequence")
in the patch method.

1) Do you have anyway to workaround this?
2) What toCdata method is used for? Any real example?

Aug 2, 2016 at 8:52 AM
Don't worry about the project I see now the problem you are trying to solve. It looks like you are trying to set an action condition. This is what wasn't clear for me.

> Why CDATA has been removed from conditions by default?
I am not sure Wix# ever used CData by default for all WiX types/elements. (Though may be I just don't remember).
Anyway, currently Wix# checks if the Condition value has any XML delimiter and encodes it as a CData if any detected. However it looks like in your case the detection algorithm failed and Wix# missed that fact that your Condition interferes with XML encoding. That is why I really need to know what was your condition value that did not trigger the CData encoding.

> ...It looks like for example, that document.Root.Select("Product") returns a value, but can't reach:...
Correct. You are using XDocument Element to access it and most likely it can be only accessed with use of proper XML namespaces. Anyway, I always encourage users to use Wix# XML extensions for accessing the elements transparently by the "local names". The syntax that you were looking for is as follows:
static void Project_WixSourceGenerated(XDocument document)
    var element = document.Root.Select("Product/InstallExecuteSequence")
                                .First(x => x.Value == "MY_CONDITION");

    element.ReplaceNodes(new Condition("<your condition>").ToCData());
However in your case you don't have to do XML injection as you can force CData encoding in a more direct way:
AutoElements.ForceCDataForConditions = true;
As for the auto detection of CData triggering conditions I will proceed with the fix when I have a sample of the "offending" Condition value.
Aug 2, 2016 at 12:55 PM
It looks like the second point was the problem and the parsing of CDATA is ok so far.