问题
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
来源:https://stackoverflow.com/questions/14124428/nservicebus-could-not-find-a-concrete-type-mapped-to-xxx-error