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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 07:23:23

问题


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.


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/27812705/method-not-found-void-newtonsoft-json-serialization-defaultcontractresolver-se

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!