WiX: Extracting Binary-string in Custom Action yields string like "???good data"

Posted by leiflundgren on Stack Overflow See other posts from Stack Overflow or by leiflundgren
Published on 2010-04-28T16:11:05Z Indexed on 2010/04/28 16:13 UTC
Read the original article Hit count: 298

Filed under:
|

I just found a weird behaviour when attempting to extract a string from the Binary-table in the MSI.

I have a file containing "Hello world", the data I get is "???Hello world". (Literary question mark.)

Is this as intended?
Will it always be exactly 3 characters in the beginning?

Regards Leif


Sample code:

[CustomAction]
public static ActionResult CustomAction2(Session session)
{
    View v = session.Database.OpenView("SELECT `Name`,`Data` FROM `Binary`");
    v.Execute();

    Record r = v.Fetch();
    int datalen = r.GetDataSize("Data");
    System.IO.Stream strm = r.GetStream("Data");
    byte[] rawData = new byte[datalen];
    int res = strm.Read(rawData, 0, datalen);
    strm.Close();

    String s = System.Text.Encoding.ASCII.GetString(rawData);
    // s == "???Hello World"

    return ActionResult.Success;
}

© Stack Overflow or respective owner

Related posts about wix3

Related posts about custom-action