1

使用某些注册扩展方法时获取 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>
4

2 回答 2

3

从 MVC 4 升级到 MVC 5 后我遇到了这个错误,它没有更新仍然在 mvc 4 上的 autofac mvc 集成的 nuget 包,所以在所有 autofac 库的 nuget 下卸载/重新安装为我修复了这个错误。

于 2016-01-14T06:47:43.597 回答
0

我重建了测试项目的 .csproj 并且测试通过了,我没有隔离确切的问题。如果我找到它,我会在这里发布。

于 2014-01-31T18:04:51.897 回答