Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I just downloaded the latest RC and now I get this error message when I try to run web projects. I tried reinstalling .net 4.5 and uninstalling and resinstalling VS 12 RC but that hasn't worked. 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

I used fuslogvw and found out that the project was referencing the System.Web.Http.dll from here

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

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies

and set it to Copy to Local. Still it loads from gac_msil. How do I override this?

like image 364
Eonasdan Avatar asked Jun 07 '12 20:06

Eonasdan


2 Answers

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:

  1. MVC 4 VS 2010 Tools
  2. MVC 4
  3. MVC 4 (Bundle)

I uninstalled the "MVC 4" application and then my projects worked fine.

like image 197
Roet Avatar answered Oct 21 '22 10:10

Roet


For now the answer is to replace the dll from the folder

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. I hope this helps someone in the future.

I'll update if I find a better answer

like image 34
Eonasdan Avatar answered Oct 21 '22 09:10

Eonasdan