System.IO.FileLoadException: 'Loading this assembly would produce a different grant set from other



在Visual Studio 2019 V16.11.13中运行针对.Net Framework 4.7的C#MVC解决方案时,我收到了此错误(System.IO.FileLoadException:'加载此程序集将产生与其他实例不同的授予集。(HRESULT:0x80131401中的异常)')。

这个错误发生在我的Startup.cs上(请参阅带有***的代码,这就是错误发生的地方):

public void Configuration(IAppBuilder app)
{
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
bootstrapper.Initialize(CreateKernel);
HttpConfiguration config = new HttpConfiguration();
config.DependencyResolver = new NinjectResolver(bootstrapper.Kernel);
config.MapHttpAttributeRoutes();
config.EnableSwagger(c =>
{
c.Schemes(new[] { "https" });
c.SingleApiVersion("v1", "xxx");
c.PrettyPrint();
}).EnableSwaggerUi(c => { c.SupportedSubmitMethods(); });
ConfigureAuth(app);
app.UseWebApi(config);
}
private static IKernel CreateKernel()
{
**var kernel = new StandardKernel(modules);**
try
{
kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}

我已经尝试了网上找到的所有解决方案,但仍然没有得到解决方案,包括在我的注册表中添加值为1的DWord LoaderOptimization。

web.config:中尝试以下修复程序

<system.web>
...
<trust level="Full" />
</system.web>

或设置legacyCasModel="false"

如果不是问题所在,也有类似的问题可能会导致此问题,并且现在提供了受支持的修补程序,您可以参考它了解更多信息。

最新更新