Could not load type 'System.Web.Http.WebHost.Routing.Htt
本文关键字:Http Web WebHost Routing Htt System load not type Could | 更新日期: 2023-09-27 18:08:36
我尝试使用最新的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)
在Xamarin bugzilla中有一个类似的错误。显然,为了使用最新的Web API库,Mono aspnetwebstack需要首先更新:
https://bugzilla.xamarin.com/show_bug.cgi?id=19314我想我添加我的答案太晚了,但我刚刚有类似的问题,并且为了调试,我在源代码中添加了以下行:
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
所以,基本上-是的。被破坏的System.Web.dll
这可能可以通过简单地不使用config.MapHttpAttributeRoutes();
,而是手动指定Web API路由(例如config.Routes.MapHttpRoute
…)来解决。