0
votes

Can someone please explain the error below please and tell me what to do to fix it. It was working before but I am not sure what changed exactly and where for me to fix it. Your help will be much appreciated.

System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.0.4.0, Culture=neutral, PublicKeyToken='######' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json, Version=4.0.4.0, Culture=neutral, PublicKeyToken=######' ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=######' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) File name: 'Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=######' WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]. at Twitterizer.Core.TwitterCommand`1.ExecuteCommand() at Twitterizer.TwitterStatus.Update(OAuthTokens tokens, String text) at

#
2
It could be a number of things. Can you think of things that changed? Also, did you get JSON.NET from NuGet? I've had issues where I've updated JSON.NET in one assembly from NuGet but didn't update the reference in other projects, and those projects break with a similar error. - David Hoerster
@DavidHoerster I remember updating the Machine.config. - Seesharp
@DavidHoerster Thanks It was a simple error in the web.config where the current JSON is a 4.0.8.0 and not a 4.0.4.0, So I guess when I updated it using Nuget. It did not update my web.config. - Seesharp
NuGet's nice - but sometimes updating a reference can cause problems. Glad to hear you solved the issue. - David Hoerster
@DavidHoerster Thanks to your advice - Seesharp

2 Answers

2
votes

Without being able to see your project structure and a more detailed description of the problem i'm guessing that you have a missing runtime assembly.

You could try either:

  1. Adding a reference directly to the deployed project of your site (usually something like [yournamespace].Web) for the missing dll - "Newtonsoft.Json"
  2. You could add a post build step that copies the dll into your deployed bin folder (or you could copy this file there manually)

This could be caused by one of the other projects in your solution referencing NewtonSoft.Json (indirectly?) but it not being present in the deployed solutions bin folder. This is often not an issue until you are deploying to a production/testing server.

I hope this helps

0
votes

For me the issue was the following line of code in the web.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

I amended this to:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

removing the redirect and all worked correctly