Simple fix to error: “Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)”

Written by stevey on October 17th, 2014

After installing SQL Server 2012 and took out SQL server 2008 on local machine last week, today it was first time I tried to load the ..DS.Admin.Web project on local machine and when rendering the Home/Index page, got this error first:

System.MissingMethodException was unhandled by user code

HResult=-2146233069
Message=Method not found: 'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)'.
Source=System.Net.Http.Formatting
...
.Web.Admin\Global.asax.cs:line 22

Searched the error “Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)” and led to this post:

http://stackoverflow.com/questions/16756336/method-not-found-void-newtonsoft-json-serialization-defaultcontractresolver-set

So, I first tried this:

Install-Package Newtonsoft.Json –IncludePrerelease
PM> Install-Package Newtonsoft.Json –IncludePrerelease
'Newtonsoft.Json 6.0.5' already installed.
Successfully removed 'Newtonsoft.Json 4.5.1' from Corestream.PPDS.Web.Admin.
Successfully added 'Newtonsoft.Json 6.0.5' to Corestream.PPDS.Web.Admin.

But that led to a different message:

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 d
downloaded 3.5 from http://json.codeplex.com/releases/view/50552 and copied the Newtonsoft.json.dll to
C:\Empower\Development\PPDS2\Corestream.PPDS.Admin\Corestream.PPDS.Web\packages\Newtonsoft.Json.6.0.5\lib\net40\Newtonsoft.Json.dll

Thought it might be that I needed to go back to older version of newsoft.json.dll as I am developing this project in VS2010 while some other projects in VS2012; so I went to Newtonsoft site to download the 3.5 version, based on some advice given online. Did that and set the project reference to point to the Newtonsoft.Josn.dll 3.5 version. Not that was not it, still got error about assembly mismatch. Did some more search and found some even suggested removing Newtonsoft.json.dll from GAC. It proved that was nonsense as when I ran this:

Windows+R and typed assembly

The Newtonsoft assembly does not even show up – it is not in GAC, at least for my machine.

Then I tried another smart advice and added this entry to web.config:

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

Well, only bit further, this time got this error:

System.IO.FileLoadException was unhandled by user code
HResult=-2146234304
Message=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=System.Net.Http.Formatting
FileName=Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed
FusionLog=""
....

Well, finally, I realized the best and the simplest solution to this is well under my own nose and I cursed myself for wasting so much time on wandering around on the wild web – so here come the real deal that got me out of this hole:

“The Best Solution is the Simplest Solution” – it proved true again: 

  • Started a brand new project in VS2010 and chose MVC4/Internet Application template as project type.
  • After the project compiled and flied smoothly, rendering that nice Home page that has been missing for hours from me, I checked the project’s references and noticed that now it pointed to a 4.5.6 version of Newtonsoft.Json.dll, instead of 4.5.1 or 4.5.0 that I used in the troubled project. This is in the new project’s packages folder.
  • So I just went back to the troubling project and changed the reference to point to here at this 4.5.6 version that was brought in with the mighty MVC4/Internet Application wizard for my dummy project, and as I expected, everything just went back to normal and it ended my Friday afternoon on a happier note.
 

10 Comments so far ↓

  1. Mathieu Roy says:

    Wow thanks for posting this. I had the exact same issue debugging an old MVC4 project after doing a bunch of windows updates!

    I’m not sure which update actually caused this… perhaps it’s a “Security Update for Microsoft .NET Framework 4.5.1 or the Update for Microsoft Visual Studio 2013 (KB2932965)?

  2. Agustín says:

    Thanks Stevey! That’s exactly what was happening to my project. After use NS v4.5.6 all problems are gone.

  3. Abu says:

    Thx a lot. it did fix it

  4. Gopi says:

    Wow! this is the fixed my issue

  5. Strat says:

    Thanks you for this solution, it fixes my problem!

  6. Vlad says:

    Thanks, it fixed. What I did was:

    Package Manager Console:
    > Uninstall-Package Newtonsoft.Json
    > Install-Package Newtonsoft.Json -Version 4.5.6

  7. Peter says:

    I did enjoy your honest write up. I have been there numerous times, spending hours on end finding the needle in the haystack where the answer was right there …

  8. Rekha Jayaram says:

    Thanks so much for publishing. Saved me a ton of time, and worked for me.

  9. Rekha Jayaram says:

    thanks for publishing. Saved me aton of time, and fixed my problem

  10. Martin Kirk says:

    Thanks !

    fixed my issue on my website, which ran Json.Net 4.5.1 ..

    after updating to 4.5.6 the issue was fixed !

Reply to Abu