我下载了 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:
这是失败的代码
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 }
);
}
}
我从这篇文章中了解到我需要为 NuGet 开启“包含预发布” ,但是如何开启如何为 NuGet 开启“包含预发布”?