【发布时间】:2013-06-06 11:26:35
【问题描述】:
我们使用 NServiceBus.Host.exe 来托管我们的服务,并且端点的程序集与 NServiceBus.Host.exe 位于同一文件夹中。在主文件夹下,我们有一个子文件夹,其中包含处理消息的进程所需的程序集。我们遇到的问题是,当 NServiceBus.Host.exe 加载时,它会从子文件夹中找到程序集,但无法加载它们并因错误而崩溃:
未处理的异常:Magnum.StateMachine.StateMachineException:Topshelf.Internal.ServiceController1[
[NServiceBus.Hosting.Windows.WindowsHost, NServiceBus.Host, Version=3.0.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c]] during state Initial while handling OnStart ---> Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type WindowsHost, key "MyPoint.BusMessageEndPoint, MyPoint, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null" ---> System.IO.FileNotFoundException: Could not load file or assembly 'MyAssembly, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() 中发生异常
在 System.Collections.Generic.List1..ctor(IEnumerable1 集合)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at NServiceBus.Hosting.GenericHost..ctor(IConfigureThisEndpoint specifier, String[] args, IEnumerable1 defaultProfiles,String endpointName, IEnumerable1 scannableAssembliesFullName) in c:\NServiceBus-NServiceBus-3.3.5-0\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 145 at NServiceBus.Hosting.Windows.WindowsHost..ctor(Type endpointType, String[] args, String endpointName, Boolean runOtherInstallers, Boolean runInfrastructureInstallers, IEnumerable1 scannableAssembliesFullName) 在 c:\NServiceBus-NServiceBus-3.3.5-0\src\hosting\NServiceBus.Hosting .Windows\WindowsHost.cs:第 31 行
在 C:\NServiceBus-NServiceBus-3.3.5-0\src\hosting\NServiceBus.Hosting.Windows\HostServiceLocator.cs:line 41 中的 NServiceBus.Hosting.Windows.HostServiceLocator.DoGetInstance(Type serviceType, String key)
在 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in :line 0
似乎宿主以某种方式找到了程序集,但无法加载它们。我还没有找到任何方法告诉主机不要查看子文件夹内部。如果我将程序集从子文件夹移动到主文件夹(在 NServiceBus.Host.exe 所在的同一文件夹中),一切正常,但这会使我们的结构非常混乱,并且这种子文件夹方式在 NServiceBus 2.6 上工作得很好 - 现在升级到3.3.5 我们有问题。
是否有某种方法可以阻止主机加载子文件夹 - 或者如果主机在子文件夹中找到程序集,为什么它不能加载它们?这也能解决我们的问题。
如果有人可以帮助我,非常感谢。
如果我能稍微澄清一下我们的情况,我会将我的 cmets 添加到此处的答案中。感谢您的回答!
NSericeBus.Host.exe 不需要加载子文件夹中的程序集 - 它们是使用 MEF 从我们的消息端点程序集(由 NServiceBus.Host 加载)加载的。
在 NServiceBus 2.6 中,子文件夹中的程序集要么未由 NServiceBus.Host 加载,要么它可以处理它们,但现在无法这样做。在我影响它加载的内容之前,负载就崩溃了。在调试中,崩溃发生在 Configure.With() 发生之前,所以我不能告诉 NServiceBus 关闭子文件夹。
【问题讨论】:
-
我遇到了完全相同的问题,我们在 /plugin 文件夹中部署了其他 MEF 插件。你最后是不是把所有文件都放在同一个地方?
-
@RobBird 我最终将附加插件放在 NServiceBus 主机文件夹之外的文件夹中,然后从那里加载它们。我使用 NServiceBus 文件夹中的所有插件进行了测试,但这会减慢订阅者的速度,因此我不得不删除它们。我希望我可以将插件放在 NServiceBus 主机文件夹的子文件夹中,因为这样安装会更加整洁,但无法使其正常工作,因此这是我们环境的下一个最佳解决方案。
标签: nservicebus