2

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>
amit_g
  • 30,880
  • 8
  • 61
  • 118

1 Answers1

3

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

John Simons
  • 4,288
  • 23
  • 41
  • 1
    I see you are trying to upgrade to the next major release (v3) of Autofac and v3 is not backwards compatible with v2.6. Your only option is to upgrade to NServiceBus v4(we have upgraded it to v3 of Autofac), but NServiceBus v4 is currently still in Beta, but it won't be long for a full release! – John Simons Mar 05 '13 at 07:51
  • Thanks John. Is there a similar constraint on Ninject as well? – amit_g Mar 05 '13 at 22:42
  • Ninject should be fine, because we using v3 which is the latest version anyway. – John Simons Mar 07 '13 at 00:09