System.MissingMethodException in Handler


I have a Web API Controller (.NET 6.0) that publishes an event in a Get action:

public void Get()
   Random rnd = new Random();
   var message = new ObjectPropertyChangedEvent{ AiBId = rnd.Next(1, 10000), PropertyCode = "ABC", NewPropertyValue = 3.14 };

The event is defined as follows

public class ObjectPropertyChangedEvent : IEvent
   public int AiBId { get; set; }
   public string PropertyCode { get; set; }
   public double NewPropertyValue { get; set; }

and the handler

public Task Handle(ObjectPropertyChangedEvent message, IMessageHandlerContext context)
   log.Info($"Event received: Object property value changed, ObjectId = {message.AiBId}, Property code = {message.PropertyCode}, New property value = {message.NewPropertyValue}");
   return Task.CompletedTask;

The message is published and the handler receives and processes it, but just when the handler exists, an exception is thrown:

info: PostActionManager.Handlers.FromWebAPI.ObjectPropertyChangedHandler[0]
      Event received: Object property value changed, KeyObjectId = 8185, Property code = ABC, New property value = 3,14
info: NServiceBus.RecoverabilityExecutor[0]
      Immediate Retry is going to retry message 'a6332f2e-b104-4984-b943-af4b011311a3' because of an exception:
      System.MissingMethodException: Method not found: 'System.String SharedKernel.Messages.Events.ObjectPropertyChangedEvent.get_ObjectId()'.
         at PAM.Handlers.ObjectPropertyChangedHandler.Handle(ObjectPropertyChangedEvent message, IMessageHandlerContext context)
         at NServiceBus.InvokeHandlerTerminator.Terminate(IInvokeHandlerContext context) in /_/src/NServiceBus.Core/Pipeline/Incoming/InvokeHandlerTerminator.cs:line 19
         at NServiceBus.LoadHandlersConnector.Invoke(IIncomingLogicalMessageContext context, Func`2 stage) in /_/src/NServiceBus.Core/Pipeline/Incoming/LoadHandlersConnector.cs:line 42
         at NServiceBus.ScheduledTaskHandlingBehavior.Invoke(IIncomingLogicalMessageContext context, Func`2 next) in /_/src/NServiceBus.Core/Scheduling/ScheduledTaskHandlingBehavior.cs:line 22
         at NServiceBus.MutateIncomingMessageBehavior.InvokeIncomingMessageMutators(IIncomingLogicalMessageContext context, Func`2 next) in /_/src/NServiceBus.Core/MessageMutators/MutateInstanceMessage/MutateIncomingMessageBehavior.cs:line 60

Looks like a property named ObjectId is expected in the message but I don’t understand why. Thank you in advance for any hint.

Hi @adoloca

Hmm, that sounds like a framework or .NET version mismatch of some sort. Very hard to tell based on the stack trace only. Do you have a minimal reproduction sample you could send us or share here if it is not sensitive?

I’d be happy to help.


Meanwhile solved by deleting the bin and obj folders in each project. AiBId was initially called ObjectId and was a string. It somehow stayed that way despite using the Clean function on all projects.