我正在MVC中创建一个用于测试路径的测试项目。
我收到此错误
Test Name: RouteWithControllerNoActionNoId
Test FullName: test.Web.Tests.Routing.TestRoute.RouteWithControllerNoActionNoId
Test Source: d:\newtest\test.Web.Tests\Routing\TestRoute.cs : line 17
Test Outcome: Failed
Test Duration: 0:00:06.6382043
Result Message:
Test method test.Web.Tests.Routing.TestRoute.RouteWithControllerNoActionNoId threw exception:
System.MissingMethodException: Method not found: 'System.Web.Routing.RouteValueDictionary System.Web.WebPages.TypeHelper.ObjectToDictionaryUncached(System.Object)'.
Result StackTrace:
at System.Web.Mvc.RouteCollectionExtensions.CreateRouteValueDictionaryUncached(Object values)
at System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute(RouteCollection routes, String url, Object constraints)
at System.Web.Mvc.RouteCollectionExtensions.IgnoreRoute(RouteCollection routes, String url)
at test.Web.RouteConfig.RegisterRoutes(RouteCollection routes) in d:\newtest\test.Web\App_Start\RouteConfig.cs:line 15
at test.Wesb.Tests.Routing.TestRoute.RouteWithControllerNoActionNoId() in d:\newtest\test.Web.Tests\Routing\TestRoute.cs:line 21
这是我的示例代码
[TestMethod]
public void RouteWithControllerNoActionNoId()
{
// Arrange
var context = new StubHttpContextForRouting(requestUrl: "~/Home");
var routes = new RouteCollection();
RouteConfig.RegisterRoutes(routes);
// Act
RouteData routeData = routes.GetRouteData(context);
// Assert
Assert.IsNotNull(routeData);
Assert.AreEqual("Home", routeData.Values["controller"]);
Assert.AreEqual("Index", routeData.Values["action"]);
Assert.AreEqual(UrlParameter.Optional, routeData.Values["id"]);
}
我在这一行收到错误
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
在我的RouteConfig
文件中
任何人都可以帮助我吗?
答案 0 :(得分:0)
见: Mvc 5.1 MissingMethodException System.Web.WebPages.TypeHelper.ObjectToDictionaryUncached
"在References中我发现System.Web.WebPages.dll版本3.0.11001.0显示了这种类型的错误,但是当我用System.Web.WebPages.dll版本3.0.20129.0替换它时,它可以工作。因此,您应该从引用中删除旧版本并下载其他版本,而不是干净的解决方案,重建并且它将起作用。"