当 Assembly 依赖于 Automapper 时处理 onStart 时出现 NService 总线异常

发布于 2024-11-02 09:29:28 字数 3098 浏览 1 评论 0原文

我们有一个使用 Automapper.dll 引用的程序集。作为订阅者启动 NServiceBus 在启动时失败,并显示以下消息:

Exception when starting endpoint, error has been logged. Reason: Could not load file or assembly 'file:///D:\Main\Src\Core\Core.MessageHandler\bin\Debug\AutoMapper.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

StackTrace:

Server stack trace: 
       at Magnum.StateMachine.ExceptionActionDictionary`1.HandleException(T stateMachine, Event event, Object parameter, Exception exception)
       at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object parameter)
       at Magnum.StateMachine.EventActionBase`1.Execute(T instance, Event event, Object parameter)
       at Magnum.StateMachine.State`1.RaiseEvent(T instance, BasicEvent`1 eevent, Object value)
       at Magnum.StateMachine.StateMachine`1.RaiseEvent(Event raised)
       at Topshelf.Internal.ServiceController`1.Start()
       at Topshelf.Internal.IsolatedServiceControllerWrapper`1.Start()
       at Topshelf.Internal.ServiceControllerProxy.Start()
       at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Topshelf.Internal.ServiceControllerProxy.Start()
       at Topshelf.Internal.FacadeToIsolatedServiceController`1.Start()
       at Topshelf.Internal.ServiceCoordinator.Start()
       at Topshelf.Internal.Hosts.ConsoleHost.Run()
       at Topshelf.Internal.Actions.RunAsConsoleAction.Do(IRunConfiguration configuration)
       at Topshelf.Runner.Host(IRunConfiguration configuration, String[] args)
       at NServiceBus.Host.Program.Main(String[] args)

文件“Automapper.dll”存在! Config 中没有问题。我检查了这一点,删除了对 AutoMapper.dll 的依赖,并且它有效。

这是配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="MsmqTransportConfig" 
             type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
  </configSections>

  <MsmqTransportConfig 
    InputQueue="MyQueue@localhost" 
    NumberOfWorkerThreads="1" 
    MaxRetries="10" 
    ErrorQueue="ErrorQueue@localhost" />

  <Logging Threshold="WARN" />

</configuration>

有什么想法吗? NServiceBus 中的 AutoMapper 依赖项是否存在已知问题?

We have an assembly using a refernce to the Automapper.dll. Starting the NServiceBus as Subscriber fails on Start with the following message:

Exception when starting endpoint, error has been logged. Reason: Could not load file or assembly 'file:///D:\Main\Src\Core\Core.MessageHandler\bin\Debug\AutoMapper.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

StackTrace:

Server stack trace: 
       at Magnum.StateMachine.ExceptionActionDictionary`1.HandleException(T stateMachine, Event event, Object parameter, Exception exception)
       at Magnum.StateMachine.EventActionList`1.Execute(T stateMachine, Event event, Object parameter)
       at Magnum.StateMachine.EventActionBase`1.Execute(T instance, Event event, Object parameter)
       at Magnum.StateMachine.State`1.RaiseEvent(T instance, BasicEvent`1 eevent, Object value)
       at Magnum.StateMachine.StateMachine`1.RaiseEvent(Event raised)
       at Topshelf.Internal.ServiceController`1.Start()
       at Topshelf.Internal.IsolatedServiceControllerWrapper`1.Start()
       at Topshelf.Internal.ServiceControllerProxy.Start()
       at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Topshelf.Internal.ServiceControllerProxy.Start()
       at Topshelf.Internal.FacadeToIsolatedServiceController`1.Start()
       at Topshelf.Internal.ServiceCoordinator.Start()
       at Topshelf.Internal.Hosts.ConsoleHost.Run()
       at Topshelf.Internal.Actions.RunAsConsoleAction.Do(IRunConfiguration configuration)
       at Topshelf.Runner.Host(IRunConfiguration configuration, String[] args)
       at NServiceBus.Host.Program.Main(String[] args)

The file "Automapper.dll" exists! There is no problem in the Config. I checked this removing the dependency to the AutoMapper.dll and it works.

Here is the config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="MsmqTransportConfig" 
             type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
  </configSections>

  <MsmqTransportConfig 
    InputQueue="MyQueue@localhost" 
    NumberOfWorkerThreads="1" 
    MaxRetries="10" 
    ErrorQueue="ErrorQueue@localhost" />

  <Logging Threshold="WARN" />

</configuration>

Any idea? Are there known problems with AutoMapper dependencies in NServiceBus?

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

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

发布评论

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

评论(2

翻身的咸鱼 2024-11-09 09:29:28

在端点配置类 (IConfigureThisEndpoint) 中,通常也实现 IWantCustomInitialization。作为自定义初始化的一部分,您可以指定以下内容:

public void Init()
{
    Configure.With(AllAssemblies.Except("Automapper.dll"))
        .AutofacBuilder()
        .Log4Net(); // etc.
}

“AllAssemblies.Except()”代码指示 NServiceBus 配置完全忽略 Automapper 程序集。

可能导致该问题的另一个潜在问题是,如果您使用针对 CLR v2.0 (.NET v3.5) 编译的 NServiceBus.Host.exe,而 Automapper 是针对 CLR v4.0 (.NET 4.0) 编译的。 NServiceBus 有多种版本,具体取决于您的 CLR 版本。您可能需要尝试运行将 Automapper 更改为 .NET 3.5 版本的 CLR v4.0 版本(我相信该版本尚未积极开发)。

In your endpoint configuration class (IConfigureThisEndpoint) it's common to implement IWantCustomInitialization as well. As part of that custom initialization you can specify the following:

public void Init()
{
    Configure.With(AllAssemblies.Except("Automapper.dll"))
        .AutofacBuilder()
        .Log4Net(); // etc.
}

The "AllAssemblies.Except()" code instructs the NServiceBus configuration to completely ignore the Automapper assembly.

One other potential issue that may cause the issue is if you're using NServiceBus.Host.exe compiled against the CLR v2.0 (.NET v3.5) while Automapper is compiled against the CLR v4.0 (.NET 4.0). There are several builds of NServiceBus depending upon your CLR version. You may need to try running the CLR v4.0 version of change Automapper to be the .NET 3.5 version (which I believe isn't actively developed).

清秋悲枫 2024-11-09 09:29:28

我们必须使用绑定重定向才能使 Autofac + NServiceBus 正常工作。我相信我们引用的 NServiceBus.ObjectBuilder.Autofac2.dll 使用的 Autofac 版本比我们使用的旧版本。

应用程序配置:
...

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" />
    <bindingRedirect oldVersion="2.3.2.632" newVersion="2.4.3.700" />
  </dependentAssembly>
</assemblyBinding>

We had to use a binding redirect to get Autofac + NServiceBus to work. I believe the NServiceBus.ObjectBuilder.Autofac2.dll we referenced used an older version of Autofac than we were using.

app.config:
...

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" />
    <bindingRedirect oldVersion="2.3.2.632" newVersion="2.4.3.700" />
  </dependentAssembly>
</assemblyBinding>

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