Missing Config File With Binding Redirects in Pure CPP Client Wrapping .NET Library via CPP/CLI

-2

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).

Architecture

CppClientPure (client console .exe)

  • links to:

CppWrapper (static .lib compiled with /clr -- CPP/CLI)

  • references:

DevKit (.net class library)

  • references several assemblies

    The DevKit contains a reference to a third-party assembly that looks for Newtonsoft.Json, Version=3.5.0.0, 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=3.5.0.0, 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:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\clr.dll

Running under executable  E:\\tfssrc\\Builder_Mainline\\Source\\Libraries\\Managed\\etp-devkit\\etp-devkit-master\\src\\x64\\Debug\\CppClientPure.exe\r\n

--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = Newtonsoft.Json, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed\n (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 = NULL\r\nCalling 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:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\config\\machine.config.
LOG: Post-policy reference: Newtonsoft.Json, Version=3.5.0.0, 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-9.0.0.0" newVersion="9.0.0.0" />
          </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.

c++
.net
c++-cli
app-config
assembly-binding-redirect
asked on Stack Overflow Feb 17, 2021 by jslmsca

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0