I’m trying to move NServiceBus UnicastBusConfig from Web.config to (VB.NET) code and I’m having some problems doing so. The original Web.config looked like the following:
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Messages" Endpoint="TSInputQueue" />
</MessageEndpointMappings>
</UnicastBusConfig>
And when the bus was configured with this, the “assembliesToEndpoints” property ended up looking like this and everything worked OK:

Then I removed the configuration from Web.config and created a new IConfigurationSource:
Public Class UnicastBusConfigurator
Implements IConfigurationSource
Public Function GetConfiguration(Of T As Class)() As T Implements NServiceBus.Config.ConfigurationSource.IConfigurationSource.GetConfiguration
If (GetType(T) Is GetType(UnicastBusConfig)) Then
Dim mapping = New MessageEndpointMapping()
mapping.Endpoint = "InputQueue"
mapping.Messages = "Messages"
Dim unicastBusConfig As UnicastBusConfig = New UnicastBusConfig()
unicastBusConfig.MessageEndpointMappings.Add(New MessageEndpointMapping())
Return TryCast(unicastBusConfig, T)
End If
Return TryCast(ConfigurationManager.GetSection(GetType(T).Name), T)
End Function
End Class
And I added the following part to the bus initialization (for some reason the extension methods aren’t working…):
config = config.CustomConfigurationSource(New UnicastBusConfigurator)
I’ve made sure that the UnicastBusConfigurator’s GetConfiguration-method is executed, but the assembliesToEndpoints-property doesn’t look right:

Note the third row in HashTable, which is empty. Now, the config.CreateBus().Start() fails:
Spring.Objects.Factory.ObjectCreationException: Error creating object with name ‘NServiceBus.Unicast.UnicastBus’ : Error setting property values: PropertyAccessExceptionsException (1 errors); nested PropertyAccessExceptions are:
[Spring.Core.TypeMismatchException: Cannot convert property value of type [System.Collections.Hashtable] to required type [System.Collections.IDictionary] for property ‘MessageOwners’., Inner Exception: System.ArgumentException: Problem loading message assembly: —> System.ArgumentException: String cannot have zero length.
The exception seems to be caused by the empty row (“String cannot have zero length.”).
Any ideas about what I’m doing wrong?
I think the issue here is that code didn’t actually add the mapping to the collection. The code add a new empty MessageEndpointMapping. I think it should read:
This should give NSB something to map to.