【问题标题】:NServiceBus Can't Load Dependent Assemblies Within Unit TestNServiceBus 无法在单元测试中加载相关程序集
【发布时间】:2010-12-20 07:19:09
【问题描述】:

我正在尝试测试一种依赖于 NServiceBus 的方法。这是一个集成测试,所以我使用的是一个真实的 NSB 实例,而不是模拟它。由于原始应用程序使用 WithWeb() 我需要先将其换成不同的启动脚本(请参阅此问题和我的答案: How do I Unit Test NServiceBus.Configure.WithWeb()? )

现在我遇到了一个新问题。该代码在我运行时有效,但在我的测试中它在配置中失败。以下是相关的堆栈信息: 内部异常:System.IO.FileLoadException Message=无法加载文件或程序集 'file:///C:\Dev\Foo\src\IntegrationTests\bin\Debug\Antlr3.Runtime.dll' 或其依赖项之一。不支持操作。 (来自 HRESULT 的异常:0x80131515) 源=mscorlib FileName=file:///C:\Dev\Foo\src\IntegrationTests\bin\Debug\Antlr3.Runtime.dll 融合日志="" 堆栈跟踪: 在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName 文件名,字符串代码库,证据 assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark 和 stackMark,布尔 throwOnFileNotFound,布尔 forIntrospection,布尔suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef,证据 assemblySecurity,StackCrawlMark 和 stackMark,Boolean for Introspection,Boolean suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.InternalLoadFrom (字符串 assemblyFile,证据 securityEvidence,Byte [] hashValue,AssemblyHashAlgorithm hashAlgorithm,Boolean for Introspection,Boolean suppressSecurityChecks,StackCrawlMark 和 stackMark) 在 System.Reflection.Assembly.LoadFrom(字符串 assemblyFile) 在 C:\Dev\nservicebus\src\config\NServiceBus.Config\Configure.cs: 233 行中的 NServiceBus.Configure.GetAssembliesInDirectoryWithExtension(String path, String extension, String[] assemblyToSkip) 在 C:\Dev\nservicebus\src\config\NServiceBus.Config\Configure.cs: 219 行中的 NServiceBus.Configure.d__7.MoveNext() 处

如果我在集成测试中添加对 Antlr3.Runtime.dll 的引用,此错误就会消失,并被替换为无法找到 Iesi.Collections... Antlr.Runtime 和 Iesi.Collections 都是其中的一部分NServiceBus.Core.dll,所以没有理由直接在 /bin 路径中查找,而不是从该程序集中加载这些。 NServiceBus、NServiceBus.Core、NServiceBus.ObjectBuilder.StructureMap都被测试项目引用,在测试项目的bin文件夹中。

为什么 NServiceBus 没有在自己的程序集中找到它需要的程序集?

【问题讨论】:

  • 您是否尝试在自定义启动中限制扫描的程序集集?例如 Configure.With(Assembly[]).

标签: nservicebus


【解决方案1】:

我想我在玩 NSB 时遇到了这个问题。我不记得是不是同一个程序集...

我认为这与“文件:”前缀有关。我从来没有弄清楚它为什么使用那个前缀;但是,它只是试图加载程序集,因为它还没有被运行时加载。我只是在测试项目中添加了对程序集的引用,并在某处使用了其中一种类型;这样,当 NSB 被调用时,程序集就会成为成员,并且不需要加载它。

【讨论】:

    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-31
    • 2022-11-23
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多