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:
Project file has AutoGenerateBindingRedirects>true and the generated .config has
I managed to resolve it by handling
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
Check output in event log (Application).
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:
Main package uses latest Unsafe assembly version 6.0.0.0 while one of its other dependencies obviously wants 4.0.4.1.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.
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).