To invoke the correct message handlers for incoming messages, NServiceBus must be able to map the incoming transport message to a message type.
The mapping rules are as follows:
- If the message contains the
NServiceBus.header, the header value is used to find the message type. The header value may contain:
- The AssemblyQualifiedName of the message type (with or without the private key; both are supported). In cases when the assembly qualified type is not known by the endpoint, NServiceBus will fall back to any loaded type that matches the contained FullName, even when the type resides in a different assembly.
- The FullName of the message type. NServiceBus will map it to any loaded type that matches the specified FullName, even when the type resides in a different assembly.
- The Name of the type, without the assembly name.
- If the header is missing, some serializers can optionally infer the message type based on the message payload. Serializers that support message type inference:
NServiceBus.EnclosedMessageTypesheader is missing is only supported from NServiceBus version 7.4 or higher
A custom type inference behavior can be created when type inferences cannot be done using the incoming
NServiceBus. header and the serializer is not able to infer type information using the embedded message body. The custom behavior needs to be executed in the
IncomingPhysicalMessageContext stage. It can infer the message type by inspecting any message header of body data using custom logic and add the
NServiceBus. header with the custom resolved message type.