2

I get the error :

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. Manifest definition does not match the assembly reference.

After adding a WebApi controller class to my ASP.NET MVC project. I also have SignalR in my project. Both are using Newtonsoft.Json but it seems that they are not referencing the same version.

SignalR uses and works with the 6.0.8 Version, while the error tell me that MapHttpRoute :

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        RouteTable.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
    }

tries to load 4.5 version.

I read this post SignalR & WebApi - colliding Newtonsoft.Json references

but I don't know how to tell webapi to point on the 6.0.8 version.

Community
  • 1
  • 1
Morgan
  • 476
  • 9
  • 23
  • The linked question is *very old* and doesn't apply. Add the relevant NuGet packages instead of adding references to the assemblies. NuGet will resolve all conflicts when you install the packages – Panagiotis Kanavos Sep 30 '16 at 14:58
  • When you say adding the relevant NuGet packages, you mean installing Newtonsoft.Json via NuGet ? Because I already tried this, and updated it with the Version 9.0.0 and both SignalR and WebApi were crashing, because they could not find the assembly – Morgan Sep 30 '16 at 15:03
  • Both Json.NET and SignalR. SignalR itself is another NuGet package. Try with a clean project first though, otherwise you'll have to remove any redirections you already added in app.config – Panagiotis Kanavos Sep 30 '16 at 15:05
  • I have already installed SignalR via NuGet and now I have updated Newtonsoft.json. And it's still crashing for the same reason. I removed every redirection from the web.config and it doesn't change anything. I will try from a clean project – Morgan Sep 30 '16 at 15:14

1 Answers1

3

You can use AssemblyBinding to redirect to you installed Newtonsoft.Json assembly. Just add in your Web.config

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

This will redirect all calls with the wrong version to your installed version 6.0.8

Rabban
  • 2,451
  • 1
  • 19
  • 21