Skip to main content
 首页 » 编程设计

c#之安装 CORS 时出现 TypeInitializationException

2024年02月06日13yjmyzz

我制作了一个 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