Event identified as event type by Modified NServiceBus Marker Interfaces but does not match message type convention

Hi,

I have created a class library with a couple of interfaces IEvent and ICommand. The aim here was to allow projects to reference our class library to mark a class as a message, without needing to reference NServiceBus package directly.

I then created a custom convention as follows:

private void DefineEventConvention(ConventionsBuilder conventions)
 {
    conventions.DefiningEventsAs(type => typeof(MyLibrary.Interfaces.IEvent).IsAssignableFrom(type));
}

When I do this the below error message is logged on every event sent.

MyService.Contract.OrderPlacedEvent identified as event type by Modified NServiceBus Marker Interfaces but does not match message type convention. Treating as a message

The strange thing is, that using the learning transport the Event is published and received correctly by the message handler (even though the error message is still logged). But when the transport is switched to AzureServiceBus, the event is published, but never received by the message handler.

When I replace MyLibrary.IEvent with NServiceBus.IEvent, everything also works as expected (with no error message logged anymore). The question I have is, am I missing something when defining a convention? From reading the docs on conventions, it doesn’t appear that I am. I was also unable to find a reference to the exact error I am seeing else where. I would ideally like a solution that will still allow for engineers to mark a class as a message, without having to reference the NServiceBus NuGet package.

Hey @igobl,

A few things:

  1. Are you also spcifying conventions for DefiningCommandsAs and DefiningMessagesAs? The message is a little confusing in this context, but it’s talking about the difference between being defined as an event (replacement for NServiceBus.IEvent and a message (replacement for NServiceBus.IMessage which is mostly used for replies).
  2. Are you doing context.Publish(…) for this event? You mentioned “logged on every event sent” which makes me curious. Events need to be published.
  3. The message you’re talking about is a debug-level statement. If you set your logging level to Info you shouldn’t even see this.
  1. I have specified a convention for DefiningCommandAs, but not for DefiningMessageAs. I will try also adding a message convention and see does that make any difference. I’ll report back if it does.
  2. Apologies I mispoke, yes I am publishing the event, not sending.
  3. Well I suppose seeing the log message isn’t exactly the issue I’m focused on. The real issue is that when I switched Transports, the event was not being received by the message handler anymore until I switched back to using NServiceBus.IEvent.

Also, make sure you’re using the same conventions on both the publisher and subscriber side.

@DavidBoike you got it on the first guess :slight_smile: My issue was that I had not defined a message convention. I guess I had incorrectly assumed that if a class was identified as an Event, it would automatically also be identified as a message.

Thanks for the help