Resolved Wix bindingRedirect not resolving

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
1,678
Location
Norway
Programming Experience
10+
I have a .Net Framework 4.8 Windows Service with a single Nuget package System.Text.Json, there are several transitive dependencies.
The service works fine when installed with InstallUtil.
Then I create a Wix msi setup and it still installs and runs, but fails at a point trying to resolve a dependency:
System.IO.FileLoadException: "Could not load file or assembly "System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or one of it's dependences. The found Assembly's manifest definition does not match the Assembly reference.
Main package uses latest Unsafe assembly version 6.0.0.0 while one of its other dependencies obviously wants 4.0.4.1.
Project file has AutoGenerateBindingRedirects>true and the generated .config has <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> for the Unsafe assembly.

I managed to resolve it by handling AppDomain.AssemblyResolve in code and return the 6.0 version, but wonder if there is another better solution, and why this fails with Wix/msi and not InstallUtil?

Attaching a sample service with Wix installer. Requires Wix Toolset v3 and VS extension from here: WiX v3 | WiX Toolset
To see working bindingRedirect run InstallUtil SampleWindowsService.exe from build folder with Developer Command Prompt as administrator.
Check output in event log (Application).
 

Attachments

  • SampleWindowsService.zip
    13.4 KB · Views: 5
Solution
I figured out the difference, for the msi installer the "Path to executable" was missing file extension ".exe". (look in Services Manager, service properties)
In .wsx I had:
XML:
<File Id="service.exe" Name="SampleWindowsService" Source="$(var.SampleWindowsService.TargetDir)SampleWindowsService.exe" KeyPath="yes" />
changing to Name="SampleWindowsService.exe" resolves it, the Name attribute can also be omitted here, Source is sufficient. I mixed it up with the name of the service used for ServiceInstall/ServiceControl.

It was still executing the Source file, but the Name definition prevented it from finding the related SampleWindowsService.exe.config file with the binding redirects.
Project file has AutoGenerateBindingRedirects>true and the generated .config has <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> for the Unsafe assembly.
So the bindingRedirects are generated, but is not read/resolving when installed by Wix/msi.
 
I figured out the difference, for the msi installer the "Path to executable" was missing file extension ".exe". (look in Services Manager, service properties)
In .wsx I had:
XML:
<File Id="service.exe" Name="SampleWindowsService" Source="$(var.SampleWindowsService.TargetDir)SampleWindowsService.exe" KeyPath="yes" />
changing to Name="SampleWindowsService.exe" resolves it, the Name attribute can also be omitted here, Source is sufficient. I mixed it up with the name of the service used for ServiceInstall/ServiceControl.

It was still executing the Source file, but the Name definition prevented it from finding the related SampleWindowsService.exe.config file with the binding redirects.
 
Solution
Back
Top Bottom