0

I recently added SharpMap to one of my projects. Then, a different project in the same solution throws this:

An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll but was not handled in user code

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=6.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 search for a solution and found this: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

But in fact it does not resolve the problem:

Update-Package : Unable to resolve dependencies. 'Newtonsoft.Json 7.0.1' is not compatible with 'SharpMap 1.1.0 constraint: Newtonsoft.Json (= 4.5.11)'.
At line:1 char:16
+  Update-Package <<<<  Newtonsoft.Json
    + CategoryInfo          : NotSpecified: (:) [Update-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

A bit more about the project structure that could be relevant to the problem:

"Project A" is the startup project using SharpMap. "Project B" is the one that fails, and "Project A" references "Project B".

Community
  • 1
  • 1
Xavier Peña
  • 7,399
  • 9
  • 57
  • 99

2 Answers2

1

You need to add a reference to a specific version of the assembly Newtonsoft.Json , and the required version is 4.5.11. The version you added is 7.0.

Don
  • 6,632
  • 3
  • 26
  • 34
1

Since SharpMap 1.1.0.0 depends on Newtonsoft.Json Version 4.5.11 you should update your project using the Packet Manager Console and the following command

Update-Package Newtonsoft.Json -version 4.5.11

This will uninstall the current version of Newtonsoft.Json and will install the (old) version 4.5.11

Another workaround would be to use an assembly version redirect, by adding the following to your app.config

<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
       <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
       <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
     </dependentAssembly>
   </assemblyBinding>
</runtime>

But this should only be used, when you are sure, that SharpMap 1.1.0.0 is able to work with the new version of Newtonsoft.Json

Jehof
  • 34,674
  • 10
  • 123
  • 155