NServiceBus Could not find a concrete type mapped

2019-08-02 22:37发布

问题:

I am trying to publish an event which is defined as an interface:

Bus.Publish<IAccountCreated>(m => { m.Key = Guid.NewGuid(); });

When using the JSON serializer, it gives me the error:

Could not find a concrete type mapped to Contracts.IAccountCreated

It works fine with the XML serializer.

My endpoint configuration:

Configure.With()
    .DefaultBuilder()
    .JsonSerializer() <-- when this is here I get the error.
    .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Website"))
    .DefiningEventsAs(t => t.Namespace != null && t.Namespace.Contains("Contracts"))

I'm using NServiceBus 3.3.3.

回答1:

It turns out that the order you do things in the fluent interface is important.

This works:

Configure.With()
    .DefaultBuilder()
    .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Website"))
    .DefiningEventsAs(t => t.Namespace != null && t.Namespace.Contains("Contracts"))
    .JsonSerializer() <-- moving this down works


标签: nservicebus