Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未找到方法';Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(布尔值)_C#_Visual Studio 2012_Json.net - Fatal编程技术网

C# 未找到方法';Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(布尔值)

C# 未找到方法';Void Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(布尔值),c#,visual-studio-2012,json.net,C#,Visual Studio 2012,Json.net,我下载了一个webapi的示例代码,我得到了这个异常 我使用Visual Studio 2012 Ultimate版本打开了此示例,并安装了newtonsoft的最新版本。运行此应用程序时出现此错误。其编译成功。 你知道为什么会出现这个错误吗?有没有办法解决这个异常 System.MissingMethodException was unhandled by user code HResult=-2146233069 Message=Method not found: 'Void New

我下载了一个webapi的示例代码,我得到了这个异常 我使用Visual Studio 2012 Ultimate版本打开了此示例,并安装了newtonsoft的最新版本。运行此应用程序时出现此错误。其编译成功。 你知道为什么会出现这个错误吗?有没有办法解决这个异常

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: 
我知道我需要为NuGet打开“包括预发布”, 但是我如何打开NuGet的“包含预发布”呢

如何打开NuGet的“包含预发布”功能

要使用“Include Prerelease”安装Json.NET,请在中运行以下命令


另一个原因可能是您的GAC中有旧版本。对我来说,该版本是在.NET 4.0 GAC中删除的,这解决了问题

在我的情况下,我只是删除RouteConfig中的以下行(它已经被删除)

在VS2012中,这应该足够了

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
您可能还需要验证控制器。 如果您不确定它们的用途,还可以删除RouteConfig中的一些类引用。在我的情况下,我只保留以下两项:

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

另一种解决方案是,如果您希望并有时间找出冲突的原因,则可以将项目生成输出详细信息设置为Detailed
(转到工具->选项->项目和解决方案->生成和运行->MSBuild项目生成输出详细信息)在构建时检查您的日志。

您能提供更多详细信息吗?嘿,我回想一下,但我想我的.NET4 Gac中有一个版本可以在这里识别,我必须删除它,以便运行时可以选择更新的版本。我不知道为什么该版本最初出现在我的Gac中。希望对我有帮助被接受的答案对我来说不起作用,但是把它从程序中删除就行了。但您是否有任何文件表明,删除此项不会导致任何问题?
  //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 }
        );
using System.Web.Mvc;
using System.Web.Routing;