带有 NServiceBus 的 ASP.NET MVC 2 无法加载请求的类型

发布于 2024-08-27 23:02:10 字数 1222 浏览 2 评论 0原文

我正在尝试将 NServiceBus 与 ASP.NET MVC 2 网站一起使用(使用 VS 2010 和 .NET 4.0 框架)。但是,当我在本地计算机上运行该网站时,出现以下错误:

无法加载一种或多种请求的类型。检索 LoaderExceptions 属性以获取更多信息。

以下是我采取的相关步骤:

  • 下载了 NServiceBus.2.0.0.1145 二进制文件
  • 在我的 asp.net mvc 应用程序中,我添加了对 NServiceBus.dll 和 NServiceBus.Core.dll 的引用
  • 在 Global.asax.cs 中我添加了:
public static IBus 总线 { get;私人套装; }
protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    注册路由(RouteTable.Routes);

    总线 = NServiceBus.Configure
        .WithWeb()
        .Log4Net()
        .DefaultBuilder()
        .XmlSerializer()
        .MsmqTransport()
            .IsTransactional(假)
            .PurgeOnStartup(假)
        .UnicastBus()
            .ImpersonateSender(假)
        .CreateBus()
        。开始();
}
  • 在 web.config 中,我添加了:
<前><代码><单播总线配置> <消息端点映射> <添加消息=“消息”端点=“MyServerInputQueue”/>

该错误表明问题出在 Global.asax.cs 文件中的第一行。是否有可能是NServiceBus在.NET 4.0下运行有问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只怪假的太真实 2024-09-03 23:02:10

检查 LoaderExceptions 并查看它抱怨的是哪个程序集,然后通过调用Configure.With(AllAssemblies.Except("problematicAssembly.dll")而不是Configure.WithWeb()来排除它,并使其余的流畅初始化代码保持不变。

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.

薄凉少年不暖心 2024-09-03 23:02:10

我也有同样的问题。当按照 Udi 的建议检查 LoaderExceptions 时,问题程序集被识别为“Antlr3.Runtime.dll”。该程序集并未在我的项目中直接引用,而是被引用的 NHibernate.dll 的依赖项。

因此,添加 With(AllAssemblies.Except("Antlr3.Runtime.dll")) 并没有为我解决这个问题,我不得不将其更改为 With(AllAssemblies.Except("NHibernate.dll"))。

因此,如果您遇到此问题并且直接排除程序集无法修复它,请尝试使用 Reflector 检查引用的程序集依赖项以确定问题的根源。希望这可以帮助有类似问题的人......

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

所谓喜欢 2024-09-03 23:02:10

与 rob 类似,但我添加了绑定重定向并解决了我的问题 - 我的 deploy.ps1 失败,我不想重新编译。

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文