The goal is to create a c++ client that can use a managed library via a wrapper so that the client project does not need to be compiled with /clr (due to legacy issues).
CppClientPure (client console .exe)
- links to:
CppWrapper (static .lib compiled with /clr — CPP/CLI)
DevKit (.net class library)
references several assemblies
The DevKit contains a reference to a third-party assembly that looks for Newtonsoft.Json, Version=126.96.36.199, that is causing a runtime failure:
System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Energistics.Etp.v11.Datatypes.MessageHeader' threw an exception. Inner Exception 1: FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=188.8.131.52, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) System.TypeInitializationException HResult=0x80131534 Message=The type initializer for 'Energistics.Etp.v11.Datatypes.MessageHeader' threw an exception.
Fusion log shows the following:
"Assembly manager loaded from: C:WindowsMicrosoft.NETFramework64v4.0.30319clr.dll Running under executable E:tfssrcBuilder_MainlineSourceLibrariesManagedetp-devkitetp-devkit-mastersrcx64DebugCppClientPure.exern --- A detailed error log follows. === Pre-bind state information === LOG: DisplayName = Newtonsoft.Json, Version=184.108.40.206, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeedn (Fully-specified)r LOG: Appbase = file:///E:/tfssrc/Builder_Mainline/Source/Libraries/Managed/etp-devkit/etp-devkit-master/src/x64/Debug/r LOG: Initial PrivatePath = NULLrnCalling assembly : Avro, Version=0.9.0.0, Culture=neutral, PublicKeyToken=b1248d7eeb9d0814. === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using host configuration file: LOG: Using machine configuration file from C:WindowsMicrosoft.NETFramework64v4.0.30319configmachine.config. LOG: Post-policy reference: Newtonsoft.Json, Version=220.127.116.11, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed LOG: Attempting download of new URL file:///E:/tfssrc/Builder_Mainline/Source/Libraries/Managed/etp-devkit/etp-devkit-master/src/x64/Debug/Newtonsoft.Json.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated."
I have added a CppClientPure.config file that contains the following binding redirect:
<?xml version="1.0" encoding="utf-8"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-18.104.22.168" newVersion="22.214.171.124" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
It is the only .config file in the output directory but it doesn’t seem like it is getting picked up and therefore, the binding redirects are not applied. According to this post, How do I use binding redirects on a .NET COM DLL with an unmanaged client? what I’m attempting seems like something possible. The solution is targetting .NET Framework 4.5.2 everywhere.
Any ideas are appreciated. Thanks.
Source: Windows Questions C++