使用某些注册扩展方法时获取 TypeLoadException。
builder.RegisterModelBinders(Assembly);
builder.RegisterModelBinderProvider();
builder.RegisterFilterProvider();
引发了以下各自的异常,但builder.RegisterControllers(Assembly)
工作正常。
TypeLoadException: Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacModelBinderProvider.GetBinder(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
at Autofac.Integration.Mvc.RegistrationExtensions.RegisterModelBinders(ContainerBuilder builder, Assembly[] modelBinderAssemblies)
TypeLoadException: Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacModelBinderProvider.GetBinder(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.
at Autofac.Integration.Mvc.RegistrationExtensions.RegisterModelBinderProvider(ContainerBuilder builder)
TypeLoadException: Inheritance security rules violated by type: 'Autofac.Integration.Mvc.AutofacFilterProvider'. Derived types must either match the security accessibility of the base type or be less accessible.
at Autofac.Integration.Mvc.RegistrationExtensions.RegisterFilterProvider(ContainerBuilder builder)
以下是相关包 packages.config 的样子:
<package id="Autofac" version="3.3.0" targetFramework="net45" />
<package id="Autofac.Mvc5" version="3.2.0" targetFramework="net45" />
<package id="Autofac.Wcf" version="3.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.1.0" targetFramework="net45" />
如果有什么安慰的话,之前的Autofac.Mvc5
包也抛出了同样的错误。
这些是 Autofac 的绑定重定向:
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>