Jerry Bian
Jerry Bian

Reputation: 4228

Could not load type 'System.Web.Http.WebHost.Routing.HttpRouteExceptionHandler' in Mono

I tried to use latest Asp.Net Web API in Mono, but the error shows like this:

System.TypeLoadException
Could not load type 'System.Web.Http.WebHost.Routing.HttpRouteExceptionHandler' from assembly 'System.Web.Http.WebHost, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): System.Web.
Exception stack trace:
  at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache (System.Web.HttpContextBase context) [0x00054] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs:128 
  at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache (System.Object o, System.EventArgs e) [0x00007] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.Web.Routing/System.Web.Routing/UrlRoutingModule.cs:88 
  at System.Web.HttpApplication+<RunHooks>c__Iterator0.MoveNext () [0x001ba] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.Web/System.Web/HttpApplication.cs:1050 
  at System.Web.HttpApplication+<Pipeline>c__Iterator1.MoveNext () [0x0073b] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.Web/System.Web/HttpApplication.cs:1260 
  at System.Web.HttpApplication.Tick () [0x00000] in /Volumes/build-root-ramdisk/mono-3.4.0/mcs/class/System.Web/System.Web/HttpApplication.cs:932 

Version Information: 3.4.0 ((no/c3fc3ba Thu May 1 22:52:17 EDT 2014); ASP.NET Version: 4.0.30319.17020

And what dlls I should include via Nuget? Currently I referenced these assemblies:

- System (from GAC)
- System.Web (from GAC)
- System.Web.Http (from Nuget)
- System.Net.Http.Formatting (from Nuget)
- System.Web.Http.WebHost (from Nuget)
- Newtonsoft.Json (from Nuget)

Upvotes: 3

Views: 5351

Answers (3)

galets
galets

Reputation: 18472

I guess I'm adding my answer too late, but I just had similar issue, and to debug, I added following line to source code:

var httpHost = new System.Web.Http.WebHost.HttpControllerHandler(null);

lo and behold, the compilation failed with (line breaks are mine here):

Global.asax.cs(116,56): error CS1684: Reference to type
 `System.Web.HttpTaskAsyncHandler' claims it is defined assembly 
 `System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a',
  but it could not be found

so, basically - yes. Busted System.Web.dll

Upvotes: 1

Chris Simpson
Chris Simpson

Reputation: 151

This possibly can be gotten around by simply not using config.MapHttpAttributeRoutes();, but instead specifying Web API routes manually (e.g. config.Routes.MapHttpRoute...).

Upvotes: 0

Vadim
Vadim

Reputation: 46

There is a similar bug in Xamarin bugzilla. Apparently Mono aspnetwebstack needs to be updated first in order to use latest Web API libraries:

https://bugzilla.xamarin.com/show_bug.cgi?id=19314

Upvotes: 3

Related Questions