Could not load file or assembly Autofac, Version=3.3.0.0
Asked Answered
V

3

15

After upgrading my project from Autofac 2.6.3.862 to 3.4.0.0, I had the following error. I even didn't add any reference to Autofac 3.3.0.0 in any project in solution.

=== 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

UPDATE: I also added the assembly redirect binding to web.config, but still had error.

<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>

I also tried to add Autofac 3.3.0.0 to GAC, but it was not effective.

Vinegary answered 9/10, 2014 at 11:16 Comment(3)
I finally downgrade Microsoft.AspNet.Mvc to 5.1.0, Autofac 3.4.0.Vinegary
I get a similar error adding a WCF reference. It looks like Autofac.Integration.Wcf wants Autofac 3.3, but I have Autofac 3.5. The binding redirect suggested below was already present and doesn't help. It helps at compile time as I can see in the build logs, but not when adding a service reference. "Could not load file or assembly 'Autofac, Version=3.3.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The system cannot find the file specified."Woolworth
I had the same problem, but a Clean and Rebuild fixed it, after changing the Web.configRonni
S
23

You probably need a binding redirect in your web.config. Mine, for version 3.5, looks like:

  <dependentAssembly>
    <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
  </dependentAssembly>
Skvorak answered 9/10, 2014 at 15:36 Comment(2)
don't forget to use a correct value on newVersion. On Visual Studio, in Solution Explorer, References, click on Autofac, and see the Version value on Properties window. On newVersion in web.config, use the value founded on Properties window.Schmid
In my case referencing the Autofac.WebApi2 nuget and setting the DependencyResolver caused the issue OP is experiencing. Binding Redirect helped fix it.Bookseller
B
0

It needs the <role name>.dll.config file added to your Solution (same level as the web.config or app.config) and be set the Copy to Output Directory property to “Copy Always”. This file should contain the bindingRedirect settings. I've had the same error: FileLoadException: Could not load file or assembly in WebRole (recycling instance)

More info at Cloud Services roles recycling with the error “System.IO.FileLoadException: Could not load file or assembly”

Buckels answered 12/3, 2016 at 11:59 Comment(0)
R
0

I had this problem with a unit test library that I migrated from the old XAML builds to the new vNext builds. I had configured assembly version binding redirection for all libraries that use AutoFac. I still ended up with the problem in the output.

I eventually discovered that the binding redirect information is only output (in the bin folder) for the DLL corresponding to the project, and not all other DLLs that are included. In my case, I had a reference to another (unit test) library that also needed AutoFac. This library had unit tests in it that were also detected by the build process, and failed when run. The problem was that the binding redirects defined in the referenced library were not being applied because the referenced library's .config file was not present in the bin folder.

So I solved this by not having unit test libraries reference other unit test libraries. As a work-around, use a common code project, or a common C# project library for common code.

There is additional info about why assembly binding is required for AutoFac here: Why don’t all Autofac packages target the latest Autofac core?

Retharethink answered 25/10, 2016 at 21:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.