Install-Package...">

A type initializer for "System.Web.Http.GlobalConfiguration" threw an exception

I 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:

A type initializer for "System.Web.Http.GlobalConfiguration" threw an exception.

This is my internal exception:

{"Attempted method" System.Web.Http.GlobalConfiguration..cctor () 'to access field' System.Web.Http.GlobalConfiguration.CS $ <> 9__CachedAnonymousMethodDelegate2 'failed. "}

+51
c # asp.net-mvc cors
Sep 30 '13 at 9:50
source share
3 answers

I ran into the same issue and found a blog post in it. According to this blog post, if you use a 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 the 5.1.0-rc1 release.

+95
Oct 14 '13 at 14:24
source

I had this problem using NET 4.6.1, and after several hours of research, removing this from web.config finally fixed the problem:

 <runtime> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> </dependentAssembly> </runtime> 
+6
Feb 07 '17 at 3:14
source

I had the same problem. Definitely Kors doesn't work with me!

What I did to solve my problem with Cross Domain in WebApi was removing Cors and changing my web.config

If you enter the following lines inside your web.config, you will have WebApi enabled with the cross-domain enabled.

<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Methods" value="GET, POST, OPTIONS, PUT, DELETE" /> </customHeaders> </httpProtocol> </system.webServer>

+2
Apr 17 '15 at 14:30
source



All Articles