尝试通过安全透明方法访问安全关键类型失败

时间:2016-11-02 10:33:33

标签: 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.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.

我尝试了以下链接中给出的不同解决方案,但它们都不适用于我 Attempt by security transparent method to access security critical method failed

Attempt by security transparent method xxx to access security critical yyhttps://forums.asp.net/t/1939805.aspx

请帮忙

2 个答案:

答案 0 :(得分:3)

我很确定这是版本问题。我错误地安装了Autofac.WebApi,Autofac的版本自动为3.x.x.然后问题来了。之后我意识到我必须使用Autofac.WebApi2而不是Autofac.WebApi。我安装了,Autofac版本上升到4.6.2,然后booom问题解决了。

希望有所帮助

答案 1 :(得分:2)

我将Autofac 4.0.0版本的Autofac 3.5.0和Autofac.Integration.Mvc替换为3.0.0。这解决了问题