views:

547

answers:

2

I am trying to use NServiceBus with an ASP.NET MVC 2 website (using VS 2010 and the .NET 4.0 framework). However, when I run the site on my local machine, I get the following error:

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

Here are the relevant steps I have taken:

  • Downloaded the NServiceBus.2.0.0.1145 binaries
  • In my asp.net mvc app, I've added references to NServiceBus.dll and NServiceBus.Core.dll
  • In Global.asax.cs I've added:
public static IBus Bus { get; private set; }
protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);

    Bus = NServiceBus.Configure
        .WithWeb()
        .Log4Net()
        .DefaultBuilder()
        .XmlSerializer()
        .MsmqTransport()
            .IsTransactional(false)
            .PurgeOnStartup(false)
        .UnicastBus()
            .ImpersonateSender(false)
        .CreateBus()
        .Start();
}
  • In web.config, I've added:
<MsmqTransportConfig 
  InputQueue="MyWebClient" 
  ErrorQueue="error" 
  NumberOfWorkerThreads="1" 
  MaxRetries="5"/>

<UnicastBusConfig>
  <MessageEndpointMappings>
    <add Messages="Messages" Endpoint="MyServerInputQueue"/>
  </MessageEndpointMappings>
</UnicastBusConfig>

The error indicates that the problem is with the first line in the Global.asax.cs file. Is it possible that there is a problem with NServiceBus running under .NET 4.0?

+4  A: 

Check the LoaderExceptions and see which assembly it's complaining about, then exclude it by calling Configure.With(AllAssemblies.Except("problematicAssembly.dll") instead of Configure.WithWeb() and leave the rest of the fluent initialization code the same.

Udi Dahan
I'm having a similar problem. Maybe this is a dumb question, but where do I check the LoaderExceptions? I'm pretty new to using IoC containers, which is probably the problem. Thx-
Dave Nichol
LoaderExceptions is a property of the exception thrown.
Udi Dahan
+1  A: 

I had the same problem. When checking the LoaderExceptions as Udi suggests, the problem assembly was identified as "Antlr3.Runtime.dll". This assembly was not directly referenced in my project but was a dependency of NHibernate.dll which was referenced.

Therefore, adding With(AllAssemblies.Except("Antlr3.Runtime.dll")) didn't fix it for me, i had to change it to With(AllAssemblies.Except("NHibernate.dll")).

So if you get this problem and excluding the assembly directly doesn't fix it the try examining your referenced assembly dependencies with Reflector to identify the source of the problem. Hope this helps someone with a similar problem...

rob bentley