开发者

ASP.NET MVC 2 with NServiceBus unable to load requested types

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="Messa开发者_JAVA技巧ges" 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?


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.


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...


Similar to rob but I added a binding redirect and solved my problem - my deploy.ps1 failed and i didn't want to recompile.

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜