[英]visual studio 2012 RC Could not load type System.Web.Http.RouteParameter
I had VS 11 Beta, .net 4.5 and MVC 4 beta installed on my PC. 我在我的电脑上安装了VS 11 Beta,.net 4.5和MVC 4 beta。 I just downloaded the latest RC and now I get this error message when I try to run web projects. 我刚下载了最新的RC,现在我在尝试运行Web项目时收到此错误消息。 I tried reinstalling .net 4.5 and uninstalling and resinstalling VS 12 RC but that hasn't worked. 我尝试重新安装.net 4.5并卸载和树脂安装VS 12 RC,但这没有用。 I tried the suggestion here which didn't work either. 我尝试了这里的建议,但也没有用。
Stack 堆
Could not load type 'System.Web.Http.RouteParameter' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type 'System.Web.Http.RouteParameter' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
Source Error:
Line 26: defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
Line 27: );
Line 28: }
Line 29: }
Line 30: }
Source File: c:\projects\testNew\testNew\App_Start\RouteConfig.cs Line: 28
Stack Trace:
[TypeLoadException: Could not load type 'System.Web.Http.RouteParameter' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
testNew.RouteConfig.RegisterRoutes(RouteCollection routes) in c:\projects\testNew\testNew\App_Start\RouteConfig.cs:28
testNew.MvcApplication.Application_Start() in c:\projects\testNew\testNew\Global.asax.cs:25
[HttpException (0x80004005): Could not load type 'System.Web.Http.RouteParameter' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9841101
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Could not load type 'System.Web.Http.RouteParameter' from assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9850940
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17626
Edit 6 编辑6
I used fuslogvw
and found out that the project was referencing the System.Web.Http.dll
from here 我使用fuslogvw
并发现该项目从这里引用System.Web.Http.dll
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Http\v4.0_4.0.0.0__31bf3856ad364e35
instead of my project. 而不是我的项目。 Renaming this file made my project work but I obviously can't do this on my shared hosting site. 重命名这个文件使我的项目工作,但我显然不能在我的共享主机网站上这样做。
I've manually referenced the dll from 我手动引用了dll
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies
and set it to Copy to Local
. 并将其设置为“ Copy to Local
。 Still it loads from gac_msil
. 它仍然从gac_msil
加载。 How do I override this? 我该如何覆盖它?
I had the same problem, and found this question while googling on the error. 我有同样的问题,在谷歌上搜索错误时发现了这个问题。 When I looked at the installed programs on my windows, I saw there were 3 MVC 4 'applications' installed: 当我查看窗口上安装的程序时,我看到安装了3个MVC 4'应用程序':
I uninstalled the "MVC 4" application and then my projects worked fine. 我卸载了“MVC 4”应用程序,然后我的项目工作正常。
For now the answer is to replace the dll from the folder 目前答案是从文件夹中替换dll
C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies
into 成
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Http\v4.0_4.0.0.0__31bf3856ad364e35
upgrading over top of the Beta to the RC worked on another machine. 升级到Beta顶部到RC工作在另一台机器上。 I hope this helps someone in the future. 我希望这可以帮助将来的某个人。
I'll update if I find a better answer 如果我找到更好的答案,我会更新
I suggest you also upgrade from MVC4 Beta to MVC4 RC: http://www.asp.net/mvc/mvc4 And according to the release notes: ' You can upgrade the ASP.NET MVC 4 Developer Preview and Beta to ASP.NET MVC 4 Release Candidate without uninstalling.' 我建议你也从MVC4 Beta升级到MVC4 RC: http : //www.asp.net/mvc/mvc4并根据发行说明:'你可以将ASP.NET MVC 4 Developer Preview和Beta升级到ASP.NET MVC 4 Release Candidate,无需卸载。
And I did just that and got rid of the error. 我做到了这一点并摆脱了错误。
The reason is your app is pointing to the old MVC4 Beta in the GAC. 原因是您的应用程序指向GAC中的旧MVC4 Beta。
An alternative is using the DEVPATH environment variable mentioned at this link. 另一种方法是使用此链接中提到的DEVPATH环境变量。 http://www.christophdebaene.com/blog/2012/04/06/building-the-source-code-of-asp-net-web-api/ http://www.christophdebaene.com/blog/2012/04/06/building-the-source-code-of-asp-net-web-api/
Vincent 文森特
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.