c# - 安装 CORS 时出现 TypeInitializationException

标签 c# asp.net-web-api cors

我制作了一个 Web Api 应用程序,我想从一个单独的 使用 Ajax 的网站。

要访问 api,我需要安装 CORS,但是这样做时我得到了 错误(调试时):

An exception of type 'System.TypeInitializationException' occurred in MvcApplication1.dll but was not handled in user code Additional information: The type initializer for 'System.Web.Http.GlobalConfiguration' threw an exception**

此错误发生在 Global.asax.cs 中:

WebApiConfig.Register(GlobalConfiguration.Configuration);

重建解决方案并再次调试后,我导航到网页,然后显示另一条错误消息:

Cannot create/shadow copy 'EntityFramework' when that file already exists.**

在我安装 CORS 之前,Web Api 运行良好,除此之外 能够从另一个网站/位置访问 api,这就是我想要的......

最佳答案

候选版本应该修复错误。打开包管理器控制台并复制/粘贴以下命令。

安装包 Microsoft.AspNet.WebApi -IncludePrerelease

关于c# - 安装 CORS 时出现 TypeInitializationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26390937/

相关文章:

c# - 使用 C# 的 Google Drive API - 上传

c# - ZedGraph - 我正在寻找使用 DateTime 的示例

asp.net-web-api - client.DeleteAsync - 在正文中包含对象

java - Spring CORS 404

c# - 如何在 C# 中动态删除按钮?

angularjs - UI Bootstrap datepicker 说 ISO-8601 日期字符串的日期无效

entity-framework - 为什么 ASP.NET SPA 模板为所有请求实例化 UserManager 一次?

javascript - CORS 使用浏览器的 session cookie 获取身份验证

django - 被 CORS 策略阻止 - 从 Django 应用程序访问 S3 存储桶

c# - 验证 xml 到 xsd 以仅捕获特定错误