当我在visual studio 2012中启动一个Asp.net MVC4网站时。我被一个例外情况所困扰说:
Could not load type 'System.Net.Http.Formatting.DefaultContentNegotiator'
from assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'.
关于代码:
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
整个代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Http;
namespace Accela.Apps.Diagnostics.Portal
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Login", action = "Login", id = UrlParameter.Optional }
);
}
}
}
请帮助我离开那里。谢谢。
答案 0 :(得分:2)
看起来你有旧版本的DLL。您可以做的是,从项目中删除对“System.Net.Http.Formatting”的现有引用,然后尝试安装this
答案 1 :(得分:0)
该可选参数不仅仅是
UrlParameter.Optional
,如
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = UrlParameter.Optional }
);
而不是System.Web.Http.RouteParameter.Optional