1
votes

I'm writing an Asp.Net 5 (MVC6) web api, and I added the nuget package "SharpMap", which dependes on Newtonsoft.Json v4.5.0.0, but the asembly Mvc.Asp.Net.Mv.ViewFeatures requires Newtonsoft.Json v6.0.0.0.

If I update Newtonsoft.Json to v6 or later, I get this error:

Assembly 'Microsoft.AspNet.Mvc.ViewFeatures' with identity 'Microsoft.AspNet.Mvc.ViewFeatures, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' uses 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' which has a higher version than referenced assembly 'Newtonsoft.Json' with identity 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

Any ideas on how bypass the version restriccion of the nuget packages? Or any other solution for this particular problem?

1

1 Answers

2
votes

You can use the -IgnoreDependencies flag during install to get NuGet itself to install a package without worrying about dependency conflicts. In this case, it sounds like you would want to uninstall SharpMap, install everything else (including Json.NET 6), and then run:

Install-Package SharpMap -IgnoreDependencies

Then, we have to make .NET not complain about the conflicting versions at runtime. This can be done by adding a binding redirect to your web.config/app.config files:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="NewtonSoft.Json" />
            <bindingRedirect oldVersion="4.0.0.0-6.0.0.0"
                             newVersion="6.0.0.0"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

This tells the runtime to redirect requests to load Json.NET 4-6 to load Json.NET 6. NOTE that the versions used here are .NET assembly versions, which are not the same as NuGet package versions!

However, it's odd for a package like SharpMap to have a strict version bound on a common third-party library like NewtonSoft.Json, though. Consider asking the maintainers to provide a version with just a lower bound on that dependency (e. g. 4.5.11 or higher).