15

将我的项目从 Autofac 2.6.3.862 升级到 3.4.0.0 后,出现以下错误。我什至没有在解决方案的任何项目中添加对 Autofac 3.3.0.0 的任何引用。

=== Pre-bind state information ===
LOG: DisplayName = Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da
 (Fully-specified)
LOG: Appbase = file:///C:/Projects/Drive/temp/drive/Src/Web/
LOG: Initial PrivatePath = C:\Projects\Drive\temp\drive\Src\Web\bin
Calling assembly : Autofac.Configuration, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\Drive\temp\drive\Src\Web\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\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.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da
LOG: Attempting download of new URL file:///c:/temp/root/79371609/925ee10/Autofac.DLL.
LOG: Attempting download of new URL file:///c:/temp/root/79371609/925ee10/Autofac/Autofac.DLL.
LOG: Attempting download of new URL file:///C:/Projects/Drive/temp/drive/Src/Web/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.

Stack Trace: 


[FileLoadException: Could not load file or assembly 'Autofac, Version=3.3.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)]
   Fairfax.Classifieds.Drive.Web.Global.RegisterTypesWithAutofac() in c:\Projects\Drive\temp\drive\Src\Web\Global.asax.cs:375
   Fairfax.Classifieds.Drive.Web.Global.Application_Start(Object sender, EventArgs e) in c:\Projects\Drive\temp\drive\Src\Web\Global.asax.cs:102

[HttpException (0x80004005): Could not load file or assembly 'Autofac, Version=3.3.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)]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936485
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Could not load file or assembly 'Autofac, Version=3.3.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)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

更新:我还将程序集重定向绑定添加到 web.config,但仍然有错误。

<runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="5.2.2.0" />
            </dependentAssembly>
    <dependentAssembly>
                <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" />
                <bindingRedirect oldVersion="1.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

我也尝试将 Autofac 3.3.0.0 添加到 GAC,但没有效果。

4

3 回答 3

23

您可能需要在 web.config 中进行绑定重定向。我的,对于 3.5 版,看起来像:

  <dependentAssembly>
    <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
于 2014-10-09T15:36:43.540 回答
0

我从旧的 XAML 版本迁移到新的 vNext 版本的单元测试库遇到了这个问题。我为所有使用 AutoFac 的库配置了程序集版本绑定重定向。我仍然在输出中遇到了问题。

我最终发现,绑定重定向信息仅输出(在bin文件夹中)与项目对应的 DLL,而不是包含的所有其他 DLL。就我而言,我引用了另一个也需要 AutoFac 的(单元测试)库。该库中包含单元测试,构建过程也检测到这些单元测试,并且在运行时失败。问题是引用库中定义的绑定重定向没有被应用,因为引用库的 .config 文件不存在于bin文件夹中。

所以我通过不让单元测试库引用其他单元测试库来解决这个问题。作为一种变通方法,使用通用代码项目或通用 C# 项目库用于通用代码。

这里有关于为什么 AutoFac 需要程序集绑定的附加信息:为什么不是所有 Autofac 包都以最新的 Autofac 核心为目标?

于 2016-10-25T21:38:04.513 回答
0
于 2016-03-12T11:59:25.383 回答