C# 安全透明方法尝试访问安全关键类型失败
我在MVC4应用程序中遇到以下错误C# 安全透明方法尝试访问安全关键类型失败,c#,asp.net-mvc,asp.net-mvc-4,autofac,C#,Asp.net Mvc,Asp.net Mvc 4,Autofac,我在MVC4应用程序中遇到以下错误 Attempt by security transparent method 'Autofac.Integration.Mvc.RegistrationExtensions.RegisterControllers(Autofac.Cont ainerBuilder, System.Reflection.Assembly[])' to access security critical type 'Autofac.Builder.IRegistratio
Attempt by security transparent method 'Autofac.Integration.Mvc.RegistrationExtensions.RegisterControllers(Autofac.Cont ainerBuilder, System.Reflection.Assembly[])' to access security critical type 'Autofac.Builder.IRegistrationBuilder`3<System.Object,Autofac.Features.Scanning.ScanningActivatorData,Autofac.Builder.DynamicRegistrationStyle>' failed.
Assembly 'Autofac.Integration.Mvc, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=17863af14b0044da' is marked with the
AllowPartiallyTrustedCallersAttribute, and uses the level 2 security
transparency model. Level 2 transparency causes all methods in
AllowPartiallyTrustedCallers assemblies to become security transparent by
default, which may be the cause of this exception.
尝试通过安全透明方法“Autofac.Integration.Mvc.RegistrationExtensions.RegisterController(Autofac.containerBuilder,System.Reflection.Assembly[])访问安全关键类型“Autofac.Builder.IRegistrationBuilder`3”失败。
程序集“Autofac.Integration.Mvc,版本=3.0.0.0,区域性=中性,
PublicKeyToken=17863af14b0044da'标记为
AllowPartiallyTrustedCallersAttribute,并使用2级安全性
透明度模型。第2级透明度使所有方法都处于透明状态
允许PartiallyTrustedCallers程序集通过
默认值,这可能是导致此异常的原因。
我尝试了以下链接中给出的不同解决方案,但没有一个适合我
及
请帮助我将Autofac 4.0.0替换为Autofac 3.5.0版,并将Autofac.Integration.Mvc替换为3.0.0版。这解决了问题我很确定这就是版本问题。我错误地安装了Autofac.WebApi,Autofac的版本自动为3.x.x。然后问题来了。之后,我意识到我必须使用Autofac.WebApi而不是Autofac.WebApi。我安装了,Autofac版本升级到4.6.2,然后booom问题就解决了
希望有帮助您是否有机会查看此内容。您需要在此处添加更多内容,如您的NuGet packages.config,以便我们可以查看您引用的内容。这是解决此问题的正确方法。我还使用了WebApi而不是WebApi2