gpt4 book ai didi

asp.net-mvc - Autofac 3.4 缺失,而 3.5 被调用

转载 作者:行者123 更新时间:2023-12-01 16:59:07 27 4
gpt4 key购买 nike

尝试运行已成功构建的 MVC 5.2 项目,但出现以下错误:

An exception of type 'System.IO.FileLoadException' occurred in ProjectNamespace.WebUI.dll but was not handled in user code

Additional information: Could not load file or assembly 'Autofac, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Program Files (x86)\IIS Express\iisexpress.exe --- A detailed error log follows.

=== Pre-bind state information === LOG: DisplayName = Autofac, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da (Fully-specified) LOG: Appbase = file:///C:/ProjectPath/WebUI/ LOG: Initial PrivatePath = C:\ProjectPath\WebUI\bin Calling assembly : Autofac.Integration.Mvc, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da. === LOG: This bind starts in default load context. LOG: No application configuration file found. LOG: Using host configuration file: C:\Users\me\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: Autofac, Version=3.4.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/5c8bedab/6a36492/Autofac.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/5c8bedab/6a36492/Autofac/Autofac.DLL. LOG: Attempting download of new URL file:///C:/ProjectPath/WebUI/bin/Autofac.DLL. WRN: Comparing the assembly name resulted in the mismatch: Minor Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

我的 web.config 有以下设置:

<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>

花了几个小时试图解决这个问题,但失败了。请帮忙。

最佳答案

这个问题已经变得相当普遍。当您拥有 Autofac、Autofac.Mvc5 和 Microsoft.AspNet.Mvc>5.1.0 软件包时,似乎会出现此问题,即使 Autofac.Mvc5 据称可与 Microsoft.AspNet.Mvc(≥ 5.1.0 && < 6.0 一起使用。 0)。

  1. 我建议采用经典的解决方案,为 autofac 检查并添加适当的程序集绑定(bind)重定向,不仅在引用它的项目中,而且也在引用该项目的项目中。

  2. 另一个潜在的问题是有两个条目

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

在您的配置中,如果您的绑定(bind)位于第二个配置中,请将它们移动到第一个配置中。在我还加密了一些配置设置并且由于某种原因绑定(bind)重定向没有复制到生成的配置文件中的情况下,这为我解决了这个问题。

我强烈推荐Assembly Binding Log Viewer ,它对我解决问题有很大帮助,尽管我最终的解决方案是一个懦弱的解决方案,转到 Autofac3.4.0.0 和 Microsoft.AspNet.Mvc 5.1.0。我花了太多时间来解决这个问题。

此外,对于那些感兴趣的人,您可以使用 nuget 管理器来检测并填写程序集绑定(bind)重定向:Get-Project -All | Add-BindingRedirect(来自 here )。之后可能需要添加一些内容,具体取决于您的项目和引用资料,但至少它会给您一个干净的开始。

更新

Microsoft.AspNet.Mvc 5.2.3 已发布,所以我决定再试一次。我将涉及“冲突”的每个包更新到最新版本(Autofac 3.5.2、Autofac.Mvc5 3.3.4、Microsoft.AspNet.Mvc 5.2.3)。我更新了重定向绑定(bind)并且它起作用了。

关于asp.net-mvc - Autofac 3.4 缺失,而 3.5 被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29999572/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com