gilles27
gilles27

Reputation: 2241

Why can't NServiceBus create a proxy for my message when using XML serialization?

I've defined a message, IGetQuote, for use with NServiceBus. It's shown below, with the other types on which it depends;

public interface IGetQuote : ICommand
{
    IRisk Risk { get; set; }
}

public interface IRisk
{
    IProposer Proposer { get; }
}

public interface IProposer : IDriver
{
    string Postcode { get; set; }
}

public interface IDriver
{
    string Name { get; set; }
    void DoSomething();
}

When using the fluent API to get an IBus, I get the following exception when calling CreateBus();

System.TypeLoadException: "Method 'DoSomething' in type 'Contracts.IProposer_impl' from assembly 'Contracts_impl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.":"Contracts.IProposer__impl"

From what I understand of the way NServiceBus works, it's trying to create types that implement IGetQuote and any associated interfaces such as IProposer, in order to make the XML serialization work when the IGetQuote message is sent.

If I adjust my interfaces so that IProposer no longer inherits from IDriver, the problem goes away. My initial conclusion was that the DoSomething method must be the problem, but if I make IProposer inherit IDriver again, and move the DoSomething method onto IProposer, the exception is not thrown (although I do get a warning message "Interface IProposer contains methods and therefore cannot be mapped. Be aware that non-mapped interfaces can't be used to send messages").

So it seems like the exception occurs when you have a method declared on an interface, and that interface is extended by one of the types upon which the message type depends. It's almost like the dynamic proxy generation doesn't account for interface inheritance.

Does anyone know what is going on here?

Upvotes: 0

Views: 681

Answers (1)

Adam Fyles
Adam Fyles

Reputation: 6050

The messages sent by NSB define the contract or schema between two endpoints. This does not include behaviour, but simply data. NSB will handle interface inheritance, but rightfully so it warns you about adding behvaviour to your interfaces.

Upvotes: 1

Related Questions