我在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 yy和 https://forums.asp.net/t/1939805.aspx
请帮忙
答案 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。这解决了问题