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

时间:2011-04-21 10:26:49

标签: automapper nservicebus

我们有一个使用引用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)

堆栈跟踪:

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”存在!配置中没有问题。我检查了这个删除了对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依赖项的已知问题?

2 个答案:

答案 0 :(得分:4)

在端点配置类(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,而针对CLR v4.0(.NET编译Automapper) 4.0)。 NServiceBus有几个版本,具体取决于您的CLR版本。您可能需要尝试将更改Automapper的CLR v4.0版本运行为.NET 3.5版本(我认为这种版本尚未积极开发)。

答案 1 :(得分:1)

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

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