System.InvalidOperationException: No destination could be found for message type --> Special case

801 views
Skip to first unread message

Naga Pradeep Vattikuti

unread,
Jun 22, 2015, 10:36:26 PM6/22/15
to particula...@googlegroups.com
Product name: NServiceBus
Version: 4.6.5
Stacktrace: 
```
System.InvalidOperationException: No destination could be found for message type MyCompany.Internal.MessageContracts.JazzEnrollmentResponseMessage. Check the <MessageEndpointMappings> section of the configuration of this endpoint for an entry either for this specific message type or for its assembly.
   at NServiceBus.Unicast.UnicastBus.Send(Object[] messages) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\UnicastBus.cs:line 587
   at NServiceBus.Unicast.UnicastBus.Send(Object message) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\UnicastBus.cs:line 564
   at MyCompany.Internal.MessageProcessor.CommandHandlers.EnrollmentHandler.ProcessEnrollmentRequest(OTIEnrollmentRequest request) in d:\ServiceBusJazz_NAYAN\Xyrem\MessageProcessor\CommandHandlers\EnrollmentHandler.cs:line 33
   at MyCompany.Internal.MessageProcessor.CommandHandlers.EnrollmentHandler.Handle(OTIEnrollmentRequest message) in d:\ServiceBusJazz_NAYAN\Xyrem\MessageProcessor\CommandHandlers\EnrollmentHandler.cs:line 25
   at lambda_method(Closure , Object , Object )
   at NServiceBus.Unicast.HandlerInvocationCache.Invoke(Object handler, Object message, Dictionary`2 dictionary) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\HandlerInvocationCache.cs:line 63
   at NServiceBus.Unicast.HandlerInvocationCache.InvokeHandle(Object handler, Object message) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\HandlerInvocationCache.cs:line 21
   at NServiceBus.Unicast.Behaviors.LoadHandlersBehavior.<Invoke>b__1(Object handlerInstance, Object message) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\LoadHandlersBehavior.cs:line 42
   at NServiceBus.Unicast.Behaviors.InvokeHandlersBehavior.DispatchMessageToHandlersBasedOnType(IBuilder builder, LogicalMessage toHandle, MessageHandler messageHandler) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\InvokeHandlersBehavior.cs:line 61
   at NServiceBus.Unicast.Behaviors.InvokeHandlersBehavior.Invoke(HandlerInvocationContext context, Action next) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\InvokeHandlersBehavior.cs:line 27
   at NServiceBus.Pipeline.BehaviorChain`1.InvokeNext(T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 51   at NServiceBus.Pipeline.BehaviorChain`1.Invoke(T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 34
   at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line 139
   at NServiceBus.Pipeline.PipelineExecutor.InvokeHandlerPipeline(MessageHandler handler) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line 66
   at NServiceBus.Unicast.Behaviors.LoadHandlersBehavior.Invoke(ReceiveLogicalMessageContext context, Action next) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Behaviors\LoadHandlersBehavior.cs:line 45
   at NServiceBus.Pipeline.BehaviorChain`1.InvokeNext(T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 51   at NServiceBus.Pipeline.BehaviorChain`1.Invoke(T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 34
   at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain`1 pipelineAction, T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line 139
   at NServiceBus.Pipeline.PipelineExecutor.InvokeLogicalMessagePipeline(LogicalMessage message) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line 57
   at NServiceBus.Unicast.Messages.ExecuteLogicalMessagesBehavior.Invoke(ReceivePhysicalMessageContext context, Action next) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Unicast\Messages\ExecuteLogicalMessagesBehavior.cs:line 30
   at NServiceBus.Pipeline.BehaviorChain`1.InvokeNext(T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 51   at NServiceBus.Pipeline.BehaviorChain`1.InvokeNext(T context) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 62
   at NServiceBus.Pipeline.BehaviorChain`1.<>c__DisplayClass2.<InvokeNext>b__0() in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 51
   at NServiceBus.UnitOfWork.UnitOfWorkBehavior.Invoke(ReceivePhysicalMessageContext context, Action next) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\UnitOfWork\UnitOfWorkBehavior.cs:line 24

```

Hosting type: Selfhosted
Configuration: 
```
  Bus = Configure.With()
                               .DefineEndpointName(Settings.Default.EndpointName)
                               .AutofacBuilder(Container)
                               .DefiningMessagesAs(t => t.Namespace == "MyCompany.External.Messages")
                               .UseNHibernateSubscriptionPersister()
                               .UseNHibernateTimeoutPersister(NHibernateConfig.GetConfig(), true)
                               .UnicastBus()
                               .LoadMessageHandlers<First<InitMessageBaseHandler>>()
                               .CreateBus()
                               .Start(() => Configure.Instance.ForInstallationOn<Windows>().Install());
```

EndpointMappings in configuration file: 
```
 <add  Messages="MyCompany.Internal.ProjectA" Endpoint="InternalQueueA1" />
 <add Messages="MyCompany.Internal.ProjectB" Endpoint="InternalQueueA1" />
 <add Messages="MyCompany.External.ProjectA" Endpoint="ExternalQueue" />
```

NserviceBus is throwing above error when tried to perform Bus.Send(MyCompany.Internal.ProjectA.MessageTypeA) 

Few things to note:
1. Under configuration is have defined "MyCompany.External.Messages" namespace objects to consider as IMessages. This external project uses NServiceBus 5.2.0 so i cant remove this line as myproject is using NServiceBus 4.6.5
2. When i remove this line ".DefiningMessagesAs(t => t.Namespace == "MyCompany.External.Messages")" from the configuration then it is working fine. 

Processflow:

1. MyInternal project (NserviceBus 4.6.5) sends request to ExternalProject (NServiceBus 5.2.0)
2. ExternalProject responds back with response message
3. MyInternal project converts external response to internal response via mapping
4. Sends to InternalQueueA1 for further processing (it is currently failing at this point when i have configuration line: DefiningMessagesAs(t => t.Namespace == "MyCompany.External.Messages") defined in the Bus configuration)

Daniel Marbach

unread,
Jun 24, 2015, 8:52:15 AM6/24/15
to particula...@googlegroups.com, nag.pr...@gmail.com
Hi

I'm sorry that the endpoint mappings provide inconvenience for you. I see that you are using the Messages attribute in the Xml configuration. NServiceBus assumes that what you provided in the Messages attribute is an assembly name and will map all types to the target endpoint provided in the endpoint attribute. I personally prefer to use AssemblyName and Namespace attribute as shown here


I think it makes it more explicit what we are trying to map.

There is another important thing missing in the configuration syntax. I suggest you check for 

t.Namespace != null && your convention.

DefiningMessagesAs(t => t.Namespace != null && t.Namespace == "MyCompany.External.Messages")

I think you would also need a command mapping for your Bus.Send in addition to the message mapping like

DefiningCommandAs(t => t.Namespace != null && t.Namespace == "MyCompany.Internal.MessageContracts...") <- not sure about your exact namespace here

Regards
Daniel

Naga Pradeep Vattikuti

unread,
Jun 24, 2015, 10:24:45 PM6/24/15
to particula...@googlegroups.com, nag.pr...@gmail.com

Hi Daniel,


After making the change to .DefiningMessagesAs by specifying namespace as MyComany.Internal.MessageContracts with ORELSE condition it worked fine.

 

What I’m not clear now is why should I define “MyComany.Internal.MessageContracts” messages to consider as IMessages in the bus configuration? All the messages in this assembly implement IMessage of NServiceBus version 4.6.5. The only reason why I specified “MyCompany.External.Messages” because that’s external message and it uses different NServiceBus version 5.2.0 

Daniel Marbach

unread,
Jun 25, 2015, 5:49:28 AM6/25/15
to particula...@googlegroups.com, nag.pr...@gmail.com
Hi

You don't need to specify the DefineMessageAs when your messages derive from IMessage, ICommand or IEvent. Can you double check?

Thanks
Daniel

Naga Pradeep Vattikuti

unread,
Jul 1, 2015, 10:33:11 PM7/1/15
to particula...@googlegroups.com, nag.pr...@gmail.com
Thanks Daniel. After specifying the namespace in the DefineMesageAs it worked fine.

However, I still fee there is some issue handling multiple versions of service bus.

Scenario:
- ProjectExternalContracts no dependency on NServiceBus (This is to allow clients to use messages/commands classes without having depedency on NServiceBus version)
- ProjectExternal with NServiceBus 5.2
- ProjectInternalContracts with NServiceBus 4.6.5
- PorjectInternal (Client service which uses ProjectExternalContracts and PrjectInternalContracts)

When ProjectInternal wants handle messages or commands of type "ProjectInternalContracts" (note: dependency on 4.6.5) and send messages or commands of type "ProjectExternalContracts" (note: there is no depencdency on NServiceBus. And all messages and commands or not of type IMessage or ICommand) to external end point

Expected configuration setup for above scenario under ProjectInternalService:
- Configuration.With
                     .DefineMessageAs(Namespace="ProjectExternalContracts") //Specifying this is required because classes(Message/Commands) in ProjectExternalContracts doesnt have any dependency on NServiceBus

Actual configuration setup for above scenario under ProjectInternalService:
- Configuration.With
                     .DefineMessageAs(Namespace="ProjectIExternalContracts" && Namespace="ProjectInternalContracts") //Not sure why NserviceBus expects namespace "ProjectInternalContracts" in the configuration to define as IMessage. ProjectInternalContracts classes already implement IMessage and/or ICommand of version 4.6.5. My problem resolved only after specifying ProjectInternalContracts in the configuration

Daniel Marbach

unread,
Jul 3, 2015, 9:49:55 AM7/3/15
to particula...@googlegroups.com, nag.pr...@gmail.com
Hi

I think I got the problem now. Because both contract assemblies reference different versions of NServiceBus you need to specify that namespace mapping. Would it be possible for you to move to unobtrusive mode entirely and therefore remove the NServiceBus reference in both contract assemblies?

Regards
Daniel

Naga Pradeep Vattikuti

unread,
Jul 6, 2015, 7:23:16 PM7/6/15
to particula...@googlegroups.com, nag.pr...@gmail.com
Hi Daniel,

You still haven't got it right 100%.

The problem is one contract assembly (ProjectInternalContracts) reference 4.6.5 and other contract (ProjectExternalContracts) doesn't reference NServiceBus.

Now coming to client I have to use unobstrusive mode for ProjectExternalContract by defining messages in the configuration as it doesn't reference any NServiceBus assemblies. But the catch is NserviceBus configuration is expecting to define IMessages for ProjectInternalContracts aswell. Why? This is not expected? ProjectInternalContracts reference 4.6.5 and all messages and commands under it implements IMessage / ICommand.

To answer your question well currently i cannot go to unobtrusive mode for ProjectInternalContracts coz of timelines.

Thanks

Daniel Marbach

unread,
Jul 21, 2015, 3:08:47 AM7/21/15
to particula...@googlegroups.com, nag.pr...@gmail.com
Hi

Defining unobtrusive mode overrides the conventions for IMessage, ICommand and IEvent. So you can have either unobtrusive mode or IMessage etc. but not both at the same time by default. But you can include IMessage, ICommend and IEvent in your custom conventions. Then both work

Regards
Daniel
Reply all
Reply to author
Forward
0 new messages