Search code examples
c#visual-studiowixsharp

WixSharp: Invalid characters in path error when adding ManagedAction to Project


I am using WixSharp v1.9.2 to create an MSI file, and I am trying to add a ManagedAction to my Project object. However, when I execute the project.BuildMsi() instruction, I get the error message "Invalid characters in the path." I am creating the ManagedAction like this:

var project = new Project(
    ProjectName,
    ...,
    new ManagedAction(
        session => {
            return ActionResult.Success;
        },
        Return.check,
        When.After,
        Step.InstallFinalize,
        Condition.NOT_Installed
    ),
    ...
);

And this is the exception that is thrown:

Invalid characters in the path.
   in System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
   in System.IO.Path.IsPathRooted(String path)
   in WixSharp.WixEntity.IncrementalIdFor(WixEntity entity)
   in WixSharp.WixEntity.get_Id()
   in WixSharp.Compiler.ProcessCustomActions(Project wProject, XElement product)
   in WixSharp.Compiler.GenerateWixProj(Project project)
   in WixSharp.Compiler.BuildWxs(Project project, String path, OutputType type)
   in WixSharp.Compiler.BuildWxs(Project project, OutputType type)
   in WixSharp.Compiler.Build(Project project, String path, OutputType type)
   in WixSharp.Compiler.Build(Project project, OutputType type)
   in EndosightSetup.Program.CreateMsiFile() in D:\Projects\Lavoro\EndosightConsole\src\deploy\EndosightSetup\Program.cs:riga 180
   in EndosightSetup.Program.<>c.<Main>b__27_2() in D:\Projects\Lavoro\EndosightConsole\src\deploy\EndosightSetup\Program.cs:riga 53
   in EndosightSetup.Program.<Main>g__ConsoleLog|27_3(Int32 value, Action doAction) in D:\Projects\Lavoro\EndosightConsole\src\deploy\EndosightSetup\Program.cs:riga 60

Can you help me understand why this error is occurring and how to resolve it?


Solution

  • Here the problem

     new ManagedAction(
            session => {
                return ActionResult.Success;
            },
    

    The lambda is used internally for a lot of string manipulation and file path building.

    And name of this lambda (action.Method.Name) is something like <<Main>$>b__0_0. You can't build a valid filename from such a name (without some kind of escaping/replacing/etc), so you get the error.

    Just replace lambda with the normal method. Something like (check and fix types if needed)

    private ActionResult CustomActionAction(Session session)
    {
       return ActionResult.Success;
    }
    
     new ManagedAction(CustomActionAction,...
    

    P.S. You can try to post an issue on github, but I'm unsure if this is really a bug or a known limitation.