1

I'm trying to install the following packages with NuGet on Visual Studio 2010

  • TweetSharp version 2.3.1 (which requires Newtonsoft.Json version 5.0.6)

  • SharpMap version 1.1.0 (which requires Newtonsoft.Json version 4.5.11)

using the following simple NuGet commands:

PM> Install-Package TweetSharp
PM> Install-Package SharpMap

however I'm getting the following dependencies error after installing the second package:

Install failed. Rolling back...
Install-Package : Updating 'Newtonsoft.Json 5.0.6' to 'Newtonsoft.Json 4.5.11' failed. Unable to find a version of 'TweetSharp' that is compatible with 'Newtonsoft.Json 4.5.11'.
At line:1 char:16
+ Install-Package <<<<  SharpMap
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

is there anyway to fix this issue? thanks in advance.

Aboud Zakaria
  • 567
  • 9
  • 25

1 Answers1

4

The problem is that SharpMap has defined the dependency to be exactly

NewtonSoft.Json = 4.5.11

Not greater than or equal, but exactly equal. The best way forward is to contact the owners of the package and ask them to loosen the requirements. It's not very useful like it is, for exactly the reason demonstrated in this question.

However, you can attempt to use the -IgnoreDependencies switch:

> Install-Package SharpMap -IgnoreDependencies

This installs only SharpMap, so you'll need to explicitly install all the other dependencies (except NewtonSoft.Json) afterwards:

> Install-Package BruTile -Version 0.7.4.4
> Install-Package Common.Logging -Version 2.0.0
> Install-Package GeoAPI -Version 1.7.2
> Install-Package NetTopologySuite -Version 1.13.2
> Install-Package NetTopologySuite.IO -Version 1.13.2
> Install-Package ProjNET4GeoAPI -Version 1.3.0.3

However, SharpMap is still going to look for NewtonSoft.Json 4.5.11, so you'll need to add an assembly binding redirect in your application configuration file:

<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-5.0.6.0"
                         newVersion="5.0.6.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This may work, but I haven't tried, because in the end, it'll depend on how you want to use these two libraries together.

The shift in major versions of Json.NET indicates that there are breaking changes between 4.x and 5.0, so if SharpMap relies on some of the features of Json.NET 4.5.11 that are affected by the breaking changes, it's not going to work.

However, in my experience, using newer versions of Json.NET with libraries compiled against older versions tend to work fine, so it's worth a shot.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736