使用某些註冊擴展方法時,獲取TypeLoadException。使用Autofac.Mvc5(3.2.0)集成時的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>
異常中提到的類標有適當的安全屬性,代碼分析不報告該項目的任何錯誤。我還用最新的軟件包測試了相同的代碼,但沒有看到問題。你的配置文件中是否有 條目? –
@ AlexMeyer-Gleaves是的,我已將bindingRedirect部分添加到我的問題中。我猜這些代碼需要更新到3.3.0.0,或者由於代碼庫使用最新版本進行編譯,因此需要將其刪除。我會試驗並回復你。謝謝! – Dave
@ AlexMeyer-Gleaves我將綁定重定向更新爲3.3.0.0,導致應用程序無法編譯,版本爲3.0.0.0。在測試中,我用x64運行它,會有所作爲嗎?我也嘗試完全刪除Autofac的所有綁定重定向,但這也不起作用。 – Dave