1
votes

NServiceBus.dll - Version 5.2.9 & NServiceBus.Host - Version 6.0.0

I am developing a workflow application with pluggable addins.

In my solution I have a NServiceBus host assembly which I host using the NServiceBus.Host.exe. To prevent scanning I have defined the EndpointConfigurationType in the NServiceBus.Host.exe.config.

<appSettings>
 <add key="EndpointConfigurationType" value="Libra.Workflow.Host.EndpointConfig, Libra.Workflow.Host" />
</appSettings>

I have verified that this config is being used because if I put some unknown type I get an error and also because me EndpointConfig class is instantiated before any scanning happens.

In the Customize method of this class I have added

public void Customize(BusConfiguration cfg)
{
  cfg.AssembliesToScan(AllAssemblies.Matching("Libra.Workflow.Messages.dll"));
  ...
}

Now when I run this project I get an error because NServiceBus is scanning all assemblies and do to the nature of System.AddIn some assemblies cannot be scanned!

This scanning happens right after Libra.Workflow.Host has been instantiated but before the Customize method is called. Here is the call stack for this scan:

at NServiceBus.Hosting.Helpers.AssemblyScanner.ScanAssembly(String assemblyPath, AssemblyScannerResults results) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Hosting\Helpers\AssemblyScanner.cs:line 153
at NServiceBus.Hosting.Helpers.AssemblyScanner.GetScannableAssemblies() in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Hosting\Helpers\AssemblyScanner.cs:line 63
at NServiceBus.GenericHost..ctor(IConfigureThisEndpoint specifier, String[] args, List`1 defaultProfiles, String endpointName, IEnumerable`1 scannableAssembliesFullName) in c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\GenericHost.cs:line 33
at NServiceBus.Hosting.Windows.WindowsHost..ctor(Type endpointType, String[] args, String endpointName, IEnumerable`1 scannableAssembliesFullName) in c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\WindowsHost.cs:line 21
at NServiceBus.Hosting.Windows.HostServiceLocator.DoGetInstance(Type serviceType, String key) in c:\BuildAgent\work\a3de8759ee491634\src\NServiceBus.Hosting.Windows\HostServiceLocator.cs:line 31
at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49

The error message I get is:

Could not enumerate all types for
'C:\msc\Trunk\Libra.Workflow\Build\Libra.Workflow.Host\AddIns\Libra.Workflow\Libra.Workflow.Processors.dll'

Why is NServiceBus scanning this DLL and how can I prevent it?

Note: Since this is an AddIn DLL, there isn't even a reference to it in the Libra.Workflow.Host nor any other related assemblies so there should be absolutely no reason for NServiceBus to have to touch it.

1
Do you need to add the Libra.Workflow.Processors.dll dependencies to the assembly scanning?Sean Farmar
The thing with add-ins is that some of their dependencies are located elsewhere, more specifically in sub folders for the running host. When I build an add-in I reference a AddInView but I set Copy Local = False so the AddInView.dll does not end up in the AddIn folder. The structure is like this: .\AddIns\Libra.Workflow\Libra.Workflow.Processors.dll .\AddInViews\Libra.Workflow.Processors.Pipeline.AddInView.dll This 2nd dll is the dependancy that the scanner cannot find. The reason it is not included with the AddIn is because all add-ins share this same AddInView.dllGunnar Valur Gunnarsson
I have however found a temporary workaround but would very much like to stop NServiceBus from scanning. The workaround is to add the additional sub folder into assembly probing in the .config file <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="AddInSideAdapters;AddInViews;Contracts;HostSideAdapters"/> </assemblyBinding> </runtime>Gunnar Valur Gunnarsson
I'm confused, you are telling NServiceBus to scan AssembliesToScan(AllAssemblies.Matching("Libra.Workflow.Messages.dll")); but you are saying you don't want it to scan??Sean Farmar

1 Answers

1
votes

One way of limiting assembly scanning done by NServiceBus.Host is to use the /scannedAssemblies switch. One caveat is to pass NServiceBus.Core and NServiceBus.Host assemblies explicitly:

NServiceBus.Host.exe /scannedAssemblies:"NServiceBus.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c" /scannedAssemblies:"NServiceBus.Host, Version=6.0.0.0, Culture=neutral, PublicKeyToken=9fc386479f8a226c"

This command will scan those NServiceBus assemblies and the assembly specified via EndpointConfigurationType app setting. If you want to specify additional assemblies (like your Libra.Workflow.Messages) you may add additional /scannedAssemblies switch.

Please see this documentation page for details: http://docs.particular.net/nservicebus/hosting/nservicebus-host/#configuring-the-endpoint-controlling-assembly-scanning-using-the-command-line.