当Assembly依赖于Automapper时,在处理onStart时NService总线异常



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

Exception when starting endpoint, error has been logged. Reason: Could not load file or assembly 'file:///D:MainSrcCoreCore.MessageHandlerbinDebugAutoMapper.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依赖的已知问题?

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

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

"AllAssemblies.Except()"代码指示NServiceBus配置完全忽略Automapper组件。

另一个可能导致问题的潜在问题是,如果你使用的是针对CLR v2.0编译的NServiceBus.Host.exe。. NET v3.5),而Automapper是针对CLR v4.0 (. NET v3.5)编译的。NET 4.0)。根据你的CLR版本,NServiceBus有几个版本。您可能需要尝试运行CLR v4.0版本的change Automapper以成为。net 3.5版本(我认为该版本尚未积极开发)。

我们必须使用绑定重定向来让Autofac + NServiceBus工作。我相信我们引用的NServiceBus.ObjectBuilder.Autofac2.dll使用的是比我们使用的更旧的autofac2版本。

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>

相关内容

  • 没有找到相关文章

最新更新