设置Autofac依赖关系解析程序会导致“访问安全关键类型ILifeTimeScope失败”异常

时间:2016-05-16 15:03:18

标签: c# .net security dependency-injection autofac

我正在尝试在web api控制器中自动注入我的解决方案的一些组件,并使用autofac来执行此操作。

为此,我在Global.asax.cs中执行以下操作:

DependencyResolver.SetResolver(new AutofacDependencyResolver(ModuleFramework.Container));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(ModuleFramework.Container);

但是,当我尝试设置autofac依赖项解析程序时,出现以下错误:

Attempt by security transparent method 

'Autofac.Integration.Mvc.RequestLifetimeScopeProvider..ctor(Autofac.ILifetimeScope)' to access security critical type 'Autofac.ILifetimeScope' failed.

Assembly 'Autofac.Integration.Mvc, Version=3.3.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.

经过一些在线搜索后,我看到他们建议重新安装Microsoft.AspNet.WebApi.WebHost的几个帖子,但不幸的是,这在我的情况下不起作用。任何人都可以向我解释核心问题是什么,也许可以采取哪些措施来解决这个问题?

0 个答案:

没有答案