对于“System.Web.Http.GlobalConfiguration'的类型初始值引发了异常 [英] The type initializer for 'System.Web.Http.GlobalConfiguration' threw an exception
问题描述
我添加了一个新的Web API项目。我安装一个Cors
PM>安装封装Microsoft.AspNet.WebApi.Cors - pre
后来,当我跑我的项目,我得到这个错误:
有关'System.Web.Http.GlobalConfiguration'的类型初始扔
一个例外。
块引用>这是我的内部异常:
{试图通过法System.Web.Http.GlobalConfiguration..cctor()来
接入领域
System.Web.Http.GlobalConfiguration.CS $<> 9__CachedAnonymousMethodDelegate2
失败了。}
块引用>解决方案我碰到同样的问题,发现一个博客帖子就可以了。根据这一博客帖子,如果你使用的候选版本应该修正这个错误
安装封装Microsoft.AspNet.WebApi -Include $ P $租赁前
从这里开始:<一href=\"http://wp.sjkp.dk/webapi-and-cors-enabled-rest-services/\">http://wp.sjkp.dk/webapi-and-cors-enabled-rest-services/
这为我工作:D
在换句话说,它是固定在
5.1.0-RC1
发布。I have added a new Web API project. I install Cors
PM> Install-Package Microsoft.AspNet.WebApi.Cors -Pre
Then when I run my project, I get this error:
The type initializer for 'System.Web.Http.GlobalConfiguration' threw an exception.
This is my inner exception:
{"Attempt by method 'System.Web.Http.GlobalConfiguration..cctor()' to access field 'System.Web.Http.GlobalConfiguration.CS$<>9__CachedAnonymousMethodDelegate2' failed."}
解决方案I came across the same issue and found a blog post on it. According to this blog post if you use the release candidate it should fix the error
Install-Package Microsoft.AspNet.WebApi -IncludePrerelease
From here: http://wp.sjkp.dk/webapi-and-cors-enabled-rest-services/
This worked for me :D
In other words, it was fixed in
5.1.0-rc1
release.这篇关于对于“System.Web.Http.GlobalConfiguration'的类型初始值引发了异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!