Could not load file or assembly Autofac

0

I have a CLI program that runs different tasks on the database every night. When trying to run the program manually I get the following error message. The code hasn't even hit Program.cs as that would output some messages to the console.

Could not load file or assembly 'Autofac, Version=4.0.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)

However, when debugging through visual studio on a local database the problem does not occur, only on our test and prod servers. There is no mismatch between Autofac versions (4.8.1) or missing references in the CLI project.

I have looked at Could not load file or assembly 'Autofac, Version=3.0.0.0 but that was not the solution. I have tried cleaning and rebuilding, without success.

We haven't had this problem earlier; it occured after our latest release. However, we haven't made any significant changes to how Autofac works, version update, or the like.

c#
.net
dependency-injection
autofac
asked on Stack Overflow Dec 7, 2018 by kumaheiyama • edited Dec 7, 2018 by kiamlaluno

1 Answer

0

The problems seems to be with a mismatch of versions after all. The program doesn't seem to recognise which version to run and defaults back to 4.0.0.0 but it should be running 4.8.1.0.

App.config isn't carried over when building for release, but there is another .config-file called the same as the program (eg. CLIProgram.exe.config). App.config contains the following rows which is not carried over to CLIProgram.exe.config when building:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.8.1.0" newVersion="4.8.1.0" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>

If I manually add those rows to the CLIProgram.exe.config it works again.

answered on Stack Overflow Dec 7, 2018 by kumaheiyama

User contributions licensed under CC BY-SA 3.0