Closed GoogleCodeExporter closed 8 years ago
Some additional information on this issue that may help:
I downloaded the Autofac sources and did some digging around. Just for fun I
tried creating an instance of UrlHelper in AutofacWebTypesModule.Load() using
the following line:
var helper = new UrlHelper(new RequestContext());
When you try to run that, you get the following exception:
System.MethodAccessException was unhandled by user code
HResult=-2146233072
Message=Attempt by security transparent method 'Autofac.Integration.Mvc.AutofacWebTypesModule.Load(Autofac.ContainerBuilder)' to access security critical method 'System.Web.Mvc.UrlHelper..ctor(System.Web.Routing.RequestContext)' 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.
Source=Autofac.Integration.Mvc
StackTrace:
at Autofac.Integration.Mvc.AutofacWebTypesModule.Load(ContainerBuilder builder) in d:\Temp\WebApplication1\Autofac\Core\Source\Autofac.Integration.Mvc\AutofacWebTypesModule.cs:line 172
at Autofac.Module.Configure(IComponentRegistry componentRegistry) in d:\Temp\WebApplication1\Autofac\Core\Source\Autofac\Module.cs:line 78
at Autofac.ContainerBuilder.Build(IComponentRegistry componentRegistry, Boolean excludeDefaultModules) in d:\Temp\WebApplication1\Autofac\Core\Source\Autofac\ContainerBuilder.cs:line 185
at Autofac.ContainerBuilder.Build(ContainerBuildOptions options) in d:\Temp\WebApplication1\Autofac\Core\Source\Autofac\ContainerBuilder.cs:line 94
at WebApplication1.MvcApplication.Application_Start() in d:\Temp\WebApplication1\WebApplication1\Global.asax.cs:line 21
InnerException:
I believe this is causing the issue above, but I'm not sure how to fix it.
Original comment by mc...@carr-engineering.com
on 18 Oct 2013 at 6:25
With regard to my comment above, I discovered that if you comment out
[assembly: AllowPartiallyTrustedCallers]
in ProductAssemblyInfo.cs, the bug disappears and everything works properly.
I don't know what implications this has on real-world deployment of this
assembly, but it looks as if Microsoft is now preventing partially trusted
callers in MVC 5.
Original comment by mc...@carr-engineering.com
on 18 Oct 2013 at 6:28
It looks like you're using MVC5, but the MVC4 packages. Try updating to the
Autofac.Mvc5 package. It's currently in beta, so you'll need to allow
pre-release packages.
As we have several successful users of the MVC5 packages, I'm going to close
this issue. If the new packages don't solve the problem, let us know. Please
include alkyl the versions of everything in your project so we can give you the
most accurate assistance.
Original comment by travis.illig
on 19 Oct 2013 at 12:05
Original issue reported on code.google.com by
mc...@carr-engineering.com
on 18 Oct 2013 at 5:37