Custom serializers

Component: NServiceBus | Nuget: NServiceBus (Version: 5.x)

Create a custom serializer

A custom serializer needs to implement IMessageSerializer interface:

Edit
class MyCustomSerializer :
    IMessageSerializer
{
    public void Serialize(object message, Stream stream)
    {
        // Add code to serialize message
        throw new NotImplementedException();
    }

    public object[] Deserialize(Stream stream, IList<Type> messageTypes = null)
    {
        // Add code to deserialize message
        throw new NotImplementedException();
    }

    public string ContentType
    {
        get { throw new NotImplementedException(); }
    }
}

In order to see sample implementations, refer to the community run serializers.

Register the serializer

Register the serializer:

Edit
busConfiguration.UseSerialization(typeof(MyCustomSerializer));
When using multiple deserializers make sure that there's only one type registered per given ContentType.

Last modified