我下載了一個webapi的示例代碼,我得到這個異常 我打開這個示例使用Visual Studio 2012最終版本,我有最新的verion newtonsoft installed.I當我運行此應用程序時得到此錯誤。它成功編譯。 任何想法爲什麼這個錯誤,有沒有辦法解決這個異常。方法沒有找到'虛擬Newtonsoft.Json.Serialization.DefaultContractResolver.set_IgnoreSerializableAttribute(布爾)
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 from this post, 它失敗
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的「包括預售」?
你能提供關於這方面的更多細節嗎? –
嘿,我把我的思想回來,但我想我有我的.NET4 Gac中的版本,可以在這裏確定http://stackoverflow.com/questions/6925043/where-is-gacutil-for-net-framework -4-0-windows-7,我必須刪除它,以便運行時可以使用新版本 https://msdn.microsoft.com/en-us/library/zykhfde0(v=vs.110 ).aspx 我不知道爲什麼該版本最初是在我的GAC中。希望有幫助 – PatrickWalker