Why did Marc need the yada.exe.config with NewtonSoft.json 11, but not with 10


#1

The original problem:

I need a little clarion/.NET help. I build a .NET assembly that has 4 nuget packages some years ago. Next I wrote a clarion class to wrap my .NET assembly. I recently updated the nuget packages. My .NET unit tests all pass without error. BUT, when I move the assemblies over to my Clarion app I am getting an exception thrown. My clarion class is sending TXT, and they are getting sent, the exception comes after the send.
The exception message is
Could not load file or assembly ‘Newtonsoft.Json, Version=9.0.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)
I have put the Newtonsoft.json.dll (version 11) in the folder where my test app runs so I am very confused why I get a version 9 exception.

The solution:

probably an issue with the bindingRedirect in the app.config. Note that in this case it is a config file for the clarion EXE that calls the wrapped .NET assembly. So if your clarion program is called invoice.exe then check the bindingRedirect in invoice.exe.config

The proposed reason:

The assembly or one of it’s dependencies is expecting to find Newtonsoft.json.dll v9.0.0.0,. The bindingRedirect in the config file let’s the thing looking for the thing know that it can also try using a different version.
The application.exe.config will know contain soethign looking like this:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>

the thing dependant on Newtonsoft.Json v9.0.0.0 will now know to look for any versions between 0.0.0.0-11.0.0.0 and give them a good old go!


#2

Hi Brahn,

If you have issues with .NET assembly binding you can see what’s happening using the Fusion Log Viewer FUSLOGVW.EXE which you’ll find in one of your .NET SDK Tools folders eg

“C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\FUSLOGVW.exe”

Run it ‘As Administrator’ - set the Log Location to ‘Custom’ and go into Settings to set the log path and ‘Enable Custom Log Path’
You can choose to log exceptions and bind errors or all binds.

The log will show you exactly what’s being searched for and where.

NB you can see lots of examples of BindingRedirect in Clarion.exe.config and ClarionCL.exe.config in your %ClarionRoot% installation folder.

Graham