NserviceBus throws exception when referencing a Nettiers assembly

1.2k Views Asked by At

We use nettiers as a our data layer, and we recently have started looking at using NServiceBus, but we have hit a wall.

We have a windows service which hosts NSB and references our Nettiers assembly.

the service is throwing an exception when the following line is encountered.

var Bus = Configure.With().SpringBuilder()
            .XmlSerializer()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

the exceptions that is throw is:

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

the loader exception message is:

Could not load file or assembly 'Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Practices.Unity, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

stacktrace is:

at System.Reflection.Module._GetTypesInternal(StackCrawlMark& stackMark)
at System.Reflection.Assembly.GetTypes()
at NServiceBus.Configure.<>c__DisplayClass1.<With>b__0(Assembly a) in d:\BuildAgent-03\work\672d81652eaca4e1\src\config\NServiceBus.Config\Configure.cs:line 122
at System.Array.ForEach[T](T[] array, Action`1 action)
at NServiceBus.Configure.With(Assembly[] assemblies) in d:\BuildAgent-03\work\672d81652eaca4e1\src\config\NServiceBus.Config\Configure.cs:line 122
at NServiceBus.Configure.With(IEnumerable`1 assemblies) in d:\BuildAgent-03\work\672d81652eaca4e1\src\config\NServiceBus.Config\Configure.cs:line 111
at NServiceBus.Configure.With(String probeDirectory) in d:\BuildAgent-03\work\672d81652eaca4e1\src\config\NServiceBus.Config\Configure.cs:line 101
at NServiceBus.Configure.With() in d:\BuildAgent-03\work\672d81652eaca4e1\src\config\NServiceBus.Config\Configure.cs:line 78
at MessageSender.Program.Main(String[] args) in C:\Development\NSBTest4\MessageSender\Program.cs:line 18

without the nettiers reference NSB works fine. Any idea what the problem is and how to solve it?

thanks.

2

There are 2 best solutions below

3
On

You can exclude the nettiers dll from scanning using With(AllAssemblies.Except("name of nettiers dll"))...

0
On

Microsoft Enterprise Library (referenced by .NetTiers) was our problem, which was in turn referencing an older version of Unity. In order to solve the problem we used the following binding redirection in the config:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.Practices.Unity.Configuration" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="1.0.0.0-2.0.414.0" newVersion="2.1.505.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Alternatively, you may want to just update the Enterprise Library to the latest version.