Method not found 'Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute (Boolean)

I downloaded the sample code for webapi and I get this exception. I opened this sample using the Visual Studio 2012 Ultimate Version, and I have the latest installation option for newtonsoft. I get this error when running this application. It compiles successfully. Any idea why this error is the way to eliminate this exception.

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 StackTrace: at System.Net.Http.Formatting.JsonContractResolver..ctor(MediaTypeFormatter formatter) at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() at System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor() at System.Web.Http.HttpConfiguration.DefaultFormatters() at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes) at System.Web.Http.GlobalConfiguration.<.cctor>b__0() at System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at System.Lazy`1.get_Value() at System.Web.Http.GlobalConfiguration.get_Configuration() at System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults, Object constraints, HttpMessageHandler handler) at System.Web.Http.RouteCollectionExtensions.MapHttpRoute(RouteCollection routes, String name, String routeTemplate, Object defaults) at WebAPIRc.RouteConfig.RegisterRoutes(RouteCollection routes) in c:\Users\viemon\Downloads\WebAPIRc\WebAPIRc\WebAPIRc\App_Start\RouteConfig.cs:line 17 at WebAPIRc.WebApiApplication.Application_Start() in c:\Users\viemon\Downloads\WebAPIRc\WebAPIRc\WebAPIRc\Global.asax.cs:line 36 InnerException: 

Here is the code where it fails

 public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //Exception error start routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); //exception error end routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); } } 

I found out that I need to enable the "Enable pre-check" for NuGet from this post , but how to enable the "Enable pre-load" for NuGet?

+7
source share
3 answers

How to enable the "Enable preboot" for NuGet?

To install Json.NET with Enable Pre- Validation, run the following command in the package manager console

 Install-Package Newtonsoft.Json –IncludePrerelease 
+9
source

Another reason for this may be if you have an older version in your GAC. For me, the version was in the .NET 4.0 GAC, fixing this problem.

+2
source

In my case, you simply delete the next line in RouteConfig (it has already been erased).

  //Exception error start routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); //exception error end 

In VS2012, this should be enough.

  routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 

You may also need to check your controller. Also remove the Class link in RouteConfig if you are not sure what they are for. In my case, I just keep these two:

 using System.Web.Mvc; using System.Web.Routing; 

Another solution, if you want, and you have time to find out what causes the conflict, you can set the multi-page version of Project Build Output to the detailed one (Go to Tools-> Options -> Project and Solutions -> Build and Run -> MSBuild project build output verbosity) and upon build check your logs.

+1
source

All Articles