Wrong session.Property's value in ElevatedManagedAction

Oct 4, 2016 at 11:15 AM
Hello, Oleg!
I set up new property "DATABASE_CONNECTION_STRING". In ElevatedManagedAction it's value is wrong.

var project = new ManagedProject("My product", dir,
        new Property("DATABASE_CONNECTION_STRING", @"Data Source=.\SQLEXPRESS;Initial Catalog=DistributeSystem; Integrated Security=SSPI"),
        new ElevatedManagedAction(CustomActions.SaveSettings, Return.check,
                When.After, Step.InstallFiles, Condition.NOT_Installed)
                    UsesProperties = "DATABASE_CONNECTION_STRING, INSTALLDIR, ProductName",
                    Execute = WixSharp.Execute.deferred
project.BeforeInstall += project_BeforeInstall;


public static ActionResult SaveSettings(Session session)
catch { }
return ActionResult.Success;

in BeforeInstall event handler e.Session.Property("DATABASE_CONNECTION_STRING") is right: @"Data Source=.\SQLEXPRESS;Initial Catalog=DistributeSystem; Integrated Security=SSPI"

in SaveSettings function session.Property("DATABASE_CONNECTION_STRING") is @"Data Source=.\SQLEXPRESS"
Oct 5, 2016 at 2:18 AM
Wix# doesn't participate in serializing/deserializing CustomActionData content. It is completely done by WiX runtime. I guess when it does this it doesn't escape the comas, which are the value delimiters and must be escaped.

Ironically 5 years ago it was the same bug reported but at that time they used semi-clumns instead of comas: http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Bug-with-Semi-colon-in-Custom-action-data-td7004749.html. Meaning that the serialization flaw is still there.

You can fix it by just replacing "," with ";" if SQLServer allows ";". But better yet just do proper escaping:
new Property(
   @"Data Source=.\SQLEXPRESS;Initial Catalog=DistributeSystem; Integrated Security=SSPI".Replace(";", "{sep}")),
MessageBox.Show(session.Property("DATABASE_CONNECTION_STRING").Replace("{sep}", ";"));