2
votes

I am getting below error in MVC4 application

 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.

I tried different solutions given in below links but none of them work for me Attempt by security transparent method to access security critical method failed

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

Please help

2
Did u get a chance to look at this .github.com/autofac/Autofac/issues/459 - FakeisMe
You need to put more in here, like your NuGet packages.config so we can see what you're referencing. - Travis Illig

2 Answers

4
votes

I am pretty sure this is the version issue. I installed Autofac.WebApi by mistake, the version of Autofac was automatically 3.x.x. Then the issue came. After that I realized I had to use Autofac.WebApi2 instead of Autofac.WebApi. I installed, Autofac version went up to 4.6.2, then booom the issue was solved.

Hope it helps

3
votes

I replaced Autofac 4.0.0 with version Autofac 3.5.0 and Autofac.Integration.Mvc to 3.0.0. This resolved the problem