Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method not found: 'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(Boolean)' (webapi and PCL)

Similar to this question, which was marked as a duplicate (so I couldn't answer it directly).

I have a webapi project, which references a PCL project. I was getting this DefaultContractResolver error intermittently.

I had tried all of the troubleshooting steps from that other question, largely involving uninstalling and reinstalling the nuget packages. Didn't help.

like image 975
dbruning Avatar asked Jan 07 '15 05:01

dbruning


2 Answers

Two other things that may help:

  1. Removing Temporary ASP.NET files (found in "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files") containing old versions of the NewtonSoft dll.
  2. Removing your NuGet package folder, clearing the NuGet package cache ("Manage NuGet Packages" -> "Settings" -> "NuGet Package Manager" -> "General" -> "Clear Package Cache", then restoring the packages
like image 107
Paul Siersma Avatar answered Oct 23 '22 10:10

Paul Siersma


The root cause of the problem for me was that both my webapi project and my PCL project were referencing Newtonsoft.Json.dll. There seemed to be some kind of race condition in Visual Studio build, so that if the PCL project was built last, it would copy its portable version of Newtonsoft.Json.dll into my webapi project's \bin directory.

The solution was simply to go into my PCL project's References, and turn off "Copy local" for Newtonsoft.Json.dll

like image 39
dbruning Avatar answered Oct 23 '22 08:10

dbruning