2
votes

I am working on a sample message handler service using NServiceBus in a .NET 4.5 project. It works fine as long as DefaultBuilder is used. To configure the container for other services with Autofac as soon as reference to Autofac is added and DefaultBuilder is changed to AutofacBuilder, I get exception as shown below. reference to NServiceBus.ObjectBuilder.Autofac.dll is already in the project.

Exception when starting endpoint, error has been logged. Reason: Could not load file or assembly 'Autofac, Version=2.6.1.841, 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)

WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

What am I doing wrong? I have tried Nuget, manual reference, changing target framework to 4.0.

EDIT

After adding the binding redirects, the error message changes to

Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2>
Autofac.Builder.IRegistrationBuilder`3.PropertiesAutowired(Autofac.PropertyWiringFlags)'.

at NServiceBus.Hosting.GenericHost.Start() in c:\BuildAgent\work\nsb.master_6\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 43
at NServiceBus.Hosting.Windows.WindowsHost.Start() in c:\BuildAgent\work\nsb.master_6\src\hosting\NServiceBus.Hosting.Windows\WindowsHost.cs:line 55
at NServiceBus.Hosting.Windows.Program.<>c__DisplayClass8.<Main>b__4(WindowsHost service) in c:\BuildAgent\work\nsb.master_6\src\hosting\NServiceBus.Hosting.Windows\Program.cs:line 97
at Topshelf.Internal.ControllerDelegates`1.StartActionObject(Object obj) in c:\Projects\TopShelfForNSB\src\Topshelf\Internal\ControllerDelegates.cs:line 17
at Topshelf.Internal.IsolatedServiceControllerWrapper`1.<>c__DisplayClass2.<set_StartAction>b__1(TService service) in c:\Projects\TopShelfForNSB\src\Topshelf\Internal\IsolatedServiceControllerWrapper.cs:line 65
at Topshelf.Internal.ServiceController`1.<.cctor>b__1(ServiceController`1 sc) in c:\Projects\TopShelfForNSB\src\Topshelf\Internal\ServiceController.cs:line 35
at Magnum.StateMachine.LambdaAction`1.Execute(T instance, Event event, Object parameter) in :line 0
at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object parameter) in :line 0

App.Config

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

1 Answers

3
votes

NServiceBus v3.3.5 uses Autofac v2.6.1.841, if you are referencing a different version you need to add binding redirects.