Int Callbacks: Could not find metadata for 'System.Int32'

I know callbacks or RPC calls in general are a big no-no. But let’s say I want to use one anyway as explained here, sending a command and waiting for the reply in a thread that is NOT an EventHandler (I’m aware of deadlocks when doing it in an EventHandler).

I added NServiceBus.Callbacks 3.0.0 nuget, along with calling EnableCallbacks(); in the configuration.

I launch the command with:

var result = await _bus.Request<int>(message).ConfigureAwait(false);
Where _bus is of type IMessageSession

And the EventHandler of the message ends with:
return context.Reply(-1);

When calling the Reply() method, it seems to have difficulty serializing the Int32 reply because it’s not implementing NServiceBus message/event/command types and get this exception:

System.Exception: Could not find metadata for 'System.Int32'.
Ensure the following:
1. 'System.Int32' is included in initial scanning. 
2. 'System.Int32' implements either 'IMessage', 'IEvent' or 'ICommand' or alternatively, if you don't want to implement an interface, you can use 'Unobtrusive Mode'.
   at NServiceBus.Unicast.Messages.MessageMetadataRegistry.GetMessageMetadata(Type messageType)
   at NServiceBus.SerializeMessageConnector.SerializeEnclosedMessageTypes(Type messageType)
   at NServiceBus.SerializeMessageConnector.<Invoke>d__1.MoveNext()

Strangely enough, this code WAS working in the past. I’m not sure which change we did that began to cause this error.

Any way for Int32 to be accepted as a valid message type for using the callback sample code?

This is definitely supported, I ran the our sample that demonstrates this on my end but couldn’t reproduce the issue. Can you try on your end and see if it work? (If yes perhaps compare the code to what you have to see if there are some differences)

I’m sorry, I missed calling EnableCallbacks on the replying endpoint. Should have double checked my config.