SignalR icon indicating copy to clipboard operation
SignalR copied to clipboard

Newtonsoft dependency mismatch

Open jaygreasley opened this issue 14 years ago • 14 comments

Hi,

I've just upgraded to SignalR 0.4.0 Part of package install tells me 'Successfully added 'Newtonsoft.Json 4.0.8' When I run up my app, I get:Could not load file or assembly 'Newtonsoft.Json, Version=4.0.7.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) So it looks like SignalR is still looking for an older Newtonsoft assembly. Can I fix this manually? Any help is much appreciated

Cheers

Jay

jaygreasley avatar Feb 15 '12 10:02 jaygreasley

Edit: I uninstalled all packages, ran Install-Package Newtonsoft.Json -Version 4.0.7 and then reinstalled the SR packages

jaygreasley avatar Feb 15 '12 15:02 jaygreasley

I have a problem and tried the above but when I install signals it replaces version 4.0.7 with 4.0.8 the error I have is: JsonReaderException: Unexpected end when reading integer, line 0, position 0

ashleymst avatar Feb 15 '12 17:02 ashleymst

NuGet automatically adds binding redirects so there's no reason to add 4.0.7.

@ashleymst Can you be more descriptive?

davidfowl avatar Feb 16 '12 01:02 davidfowl

Hello, Json.NET person here! ashleymst I think your problem is caused by a regression in Json.NET as noted here - http://json.codeplex.com/workitem/22230

I've checked in a fix - https://github.com/JamesNK/Newtonsoft.Json (at least I think I have, I'm new to GitHub)

JamesNK avatar Feb 18 '12 12:02 JamesNK

I'm having the exact same issue as Jay.

I have an old legacy "Web Site" project that I am working with. I installed SignalR with NuGet. Everything compiles fine. The binding redirect is in the web.config. I also tried uninstalling all SignalR packages, manually installing (with NuGet) Newtonsoft.Json 4.0.7, then reinstalling (with NuGet) the individual SignalR packages with -IgnoreDependencies to work around the problem @ashleymst was having. Still no luck.

Everything works perfectly in another MVC3 app.

Edit: to clarify, it actually connected with the manual install of 4.0.7, but then I got an error from JsonConvert. Something like "the value cannot be null" when calling a method in my hub.

bbobrian avatar Feb 21 '12 21:02 bbobrian

I'm also having this issue. A resolution would be appreciated - unfortunately I'm rather new to nuget so I don't really know how to contribute. =(

shadowteq avatar Mar 01 '12 15:03 shadowteq

same problem. i'm a noob so that's a contributing factor.

AndrewLane avatar Mar 01 '12 15:03 AndrewLane

But I failed to use NuGet to install SignalR so everything is "manual" for me. After adding the binding redirect the sample app started working.

AndrewLane avatar Mar 01 '12 16:03 AndrewLane

I had this exact issue and resolved it by adding this into my web.config file:

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

jessicasan avatar Mar 02 '12 22:03 jessicasan

FWIW, NuGet adds that section automatically. I'm not sure how you guys got into this state but if you give me exact repro steps it'll help.

davidfowl avatar Mar 03 '12 10:03 davidfowl

Hi David,

Fantastic library - thank you. I just encountered this problem, these are the steps I took:

  1. Loaded up my existing solution
  2. Used NuGet to install SingleR.Server. I found signalr/hubs was 404'ing in my MVC3 app, so I google'd and found http://stackoverflow.com/questions/8941595/signalr-signalr-hubs-giving-404-error that I needed to reference SignalR.Hosting.AspNet too.
  3. After that happened, signalr/hubs existed, but showed this error.

I then manually added that binding redirect to web.config and everything is working now.

Plasma avatar Mar 04 '12 05:03 Plasma

Closing this.

davidfowl avatar Mar 08 '12 02:03 davidfowl

This is still happening with new applications configured via nuget. I actually ran into this again as I was trying to build a simple repro for the issue I raised earlier - but here's a repro and workaround for this particular problem.

To reproduce the error:

  • Create a new classic ASP.NET 4.0 web application named 'SrJson_Bug'.
  • Delete the jQuery scripts from the Scripts folder.
  • Via Package Manager Console, type "install-package signalr". Note the version of NS.JSON downloaded as 4.0.8.
  • Create a test endpoint:
using SignalR;
using System.Threading.Tasks;

namespace SrJson_Bug.Endpoints {
  public class TestEndpoint: PersistentConnection {
    protected override Task OnReceivedAsync(string connectionId, string data) {
      this.Send("Test 1");

      return base.OnReceivedAsync(connectionId, data);
    }
  }
}
  • Add the route map to Global.asax:
using System;
using System.Web.Routing;
using SignalR.Hosting.AspNet.Routing;
using SrJson_Bug.Endpoints;

namespace SignalR_Bug {
    public class Global : System.Web.HttpApplication {
        void Application_Start(object sender, EventArgs e) {
            RouteTable.Routes
                .MapConnection<TestEndpoint>("test", "test/{*operation}");
        }
    }
}
  • Open 'Default.aspx' and add the following to the 'HeaderContent' placeholder:
<script src="Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR.js" type="text/javascript"></script>
<script type="text/javascript">
  $(function () {
    var cn = $.connection("/test");
    cn.received(function(data) { alert(data); });
    cn.start(function() { cn.send("test"); });
  });
</script>
  • Build the app and open your browser. Assuming you're using Chrome, launch its 'Debugging Tools' and click the 'Network' tab to watch the network traffic.
  • Navigate to default.aspx. When the page has loaded, notice the last entry in the Network list:
    • Name: negotiate /test
    • Method: POST
    • Status: 500 Internal Server Error
  • Click on the 'negotiate' entry, then click the 'Preview' tab to see the following:
Server Error in '/' Application.

Could not load file or assembly 'Newtonsoft.Json, Version=4.0.7.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)

The work-around:

  • Via Package Manager Console, type "uninstall-package newtonsoft.json -force" to remove the NS.JSON 4.0.8 package.
  • Type "install-package newtonsoft.json -version 4.0.7" to load the NS.JSON 4.0.7 package.
  • Rebuild the application and reload the page. Immediately after the page loads, an alert box should appear with the text: "Test 1".

Notes:

Adding the configuration.runtime.assemblyBinding configuration section had no obvious effect, nor did updating NS.JSON to a higher version than 4.0.8.

shadowteq avatar Mar 22 '12 14:03 shadowteq

Update your version of nuget and you won't have this issue.

davidfowl avatar Apr 03 '12 01:04 davidfowl