我尝试在Mono中使用最新的Asp.Net Web API,但错误显示如下:
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
我应该通过Nuget包括哪些dll?目前我引用了这些程序集:
- 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)
答案 0 :(得分:3)
Xamarin bugzilla中存在类似的错误。显然,需要首先更新Mono aspnetwebstack才能使用最新的Web API库:
答案 1 :(得分:1)
我想我添加的答案太晚了,但我遇到了类似的问题,为了调试,我在源代码中添加了以下代码:
var httpHost = new System.Web.Http.WebHost.HttpControllerHandler(null);
瞧,编译失败了(换行是我的):
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
所以,基本上 - 是的。 Busted System.Web.dll
答案 2 :(得分:0)
这可以通过简单地不使用config.MapHttpAttributeRoutes();
来解决,而是手动指定Web API路由(例如config.Routes.MapHttpRoute
...)。