1
votes

I'm trying to test a method that relies on NServiceBus. This is an integration test so I'm working with a real instance of NSB, not mocking it out. Since the original application uses WithWeb() I needed to first swap that out with a different startup script (see this question and my answer here: How do I Unit Test NServiceBus.Configure.WithWeb()? )

Now I've run into a new problem. The code works when I run it, but within my test it is failing in the Configuration. Here is the relevant stack information: InnerException: System.IO.FileLoadException Message=Could not load file or assembly 'file:///C:\Dev\Foo\src\IntegrationTests\bin\Debug\Antlr3.Runtime.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) Source=mscorlib FileName=file:///C:\Dev\Foo\src\IntegrationTests\bin\Debug\Antlr3.Runtime.dll FusionLog="" StackTrace: 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.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at NServiceBus.Configure.GetAssembliesInDirectoryWithExtension(String path, String extension, String[] assembliesToSkip) in c:\Dev\nservicebus\src\config\NServiceBus.Config\Configure.cs:line 233 at NServiceBus.Configure.d__7.MoveNext() in c:\Dev\nservicebus\src\config\NServiceBus.Config\Configure.cs:line 219

If I add a reference to Antlr3.Runtime.dll to my integration test, this error goes away and is replaced by one saying that it cannot find Iesi.Collections... Both Antlr.Runtime and Iesi.Collections are a part of NServiceBus.Core.dll, so there's no reason why it should be looking in the /bin path directly, rather than loading these from within that assembly. NServiceBus, NServiceBus.Core, and NServiceBus.ObjectBuilder.StructureMap are all referenced by the test project and are in the test project's bin folder.

Why is NServiceBus not finding the assemblies it needs that are within its own assembly?

1
Have you tried in your custom startup to restrict the set of assemblies that are scanned? For example Configure.With(Assembly[]).Adam Fyles

1 Answers

0
votes

I think I ran into this problem when I was playing around with NSB. I don't remember if was the same assembly...

I think it had to do with the "file:" prefix. I never did figure out why it was using that prefix; but, it's only trying to load the assembly because it isn't already loaded by the runtime. I simply added a reference to the assembly in the test project and used one of the types somewhere; that way the assembly would be in member by the time NSB got invoked and it would not need to load it.