Thursday, April 16, 2015

VS2013 MVC4 project as soon as you add json.net package you cant' compile

 As soon as you add the Json>net package in nut get on a new blank mvc 4 applicaiton project, you get this

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.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)

Source Error:

Line 17:             AreaRegistration.RegisterAllAreas();
Line 18: 
Line 19:             WebApiConfig.Register(GlobalConfiguration.Configuration);
Line 20:             FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
Line 21:             RouteConfig.RegisterRoutes(RouteTable.Routes);

Source File: c:\Users\Brown.ericw\Documents\Visual Studio 2013\Projects\AngularTest4\AngularTest4\Global.asax.cs    Line: 19 




This is the fix

<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.8.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

The key is that the version on the package is 6.0.8 and you think that's what you are supposed to use , but nope, it 6.0.0.0

No comments:

Post a Comment