Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NServiceBus: Could not find Metadata for (message)

I am attempting to publish a message as shown below

_bus.Publish(new BatchCompleted { BatchId = batch.Id});

And handle it in a BatchCompletedHandler:

public class BatchCompletedHandler: IHandleMessages<BatchCompleted>
{

    public void Handle(BatchCompleted message)
    {
          Do Some Stuff...
    }
}

Whenever I try and publish the message I get the following System.Exception:

Could not find Metadata for 'MyAssembly.BatchCompleted'. Messages need to implement either 'IMessage', 'IEvent' or 'ICommand'. Alternatively, if you don't want to implement an interface, you can configure 'Unobtrusive Mode Messages' and use convention to configure how messages are mapped.

The message does implement IEvent as shown below

[Serializable]
public class BatchCompleted : IEvent
{
    public int BatchId{ get; set; }
}

I am configuring NSB using the following code

Configure.With(MyAssembly)

The message handler is in the assembly MyAssembly and the messages are in the MyMessagesAssembly.

What am I doing wrong?

like image 655
Tom Ferguson Avatar asked Sep 24 '13 11:09

Tom Ferguson


2 Answers

NServiceBus cannot find the message type being used. The messages are in a separate assembly but the configuration causes NSB to only scan the assembly specified (MyAssembly) rather than the default behaviour of scanning all assemblies in the binaries folder.

Changing the configuration to

Configure.With()

will scan all assemblies and allow NSB to find the required message types.

I think the error message is a little misleading!

like image 179
Tom Ferguson Avatar answered Nov 03 '22 02:11

Tom Ferguson


In NSB 5 you can scan all assemblies using AssembliesToScan as explained in NServiceBus doc: http://docs.particular.net/nservicebus/hosting/assembly-scanning

If you have specified namespaces conventions, make sure that all rules are correct:

config.Conventions()
            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("..."))
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("..."))
            .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.StartsWith("..."));

I hope this will helpful

like image 30
Massimo Della Calce Avatar answered Nov 03 '22 02:11

Massimo Della Calce