AI agents: use the documentation index at llms.txt to locate machine-readable pages. This section is indexed by https://docs.particular.net/nservicebus/llms.txt. The markdown version of this page is served as plain text. An MCP server at /mcp serves the same content via the search_docs and read_doc tools; it is read-only and needs no credentials. Markdown versions of documentation pages are available by appending .md to the page URL. Directory URLs use index.md. They are served as text/plain because some retrieval backends reject text/markdown.

Custom serializers

Component:
NServiceBus
NuGet Package:
NServiceBus 10.x

Create a custom serializer

A custom serializer needs to implement the IMessageSerializer interface:

class MyCustomSerializerDefinition :
    SerializationDefinition
{
    public const string Key = "MyCustomSerializer.Settings";

    public override Func<IMessageMapper, IMessageSerializer> Configure(IReadOnlySettings settings)
    {
        return mapper =>
        {
            var value = settings.GetOrDefault<string>(Key);
            return new MyCustomSerializer(value);
        };
    }
}

class MyCustomSerializer :
    IMessageSerializer
{
    public MyCustomSerializer(string settingsValue)
    {
        // Add code initializing serializer on the basis of settingsValue
    }

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

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

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

static class MyCustomSerializerConfigurationExtensions
{
    public static void Settings(this SerializationExtensions<MyCustomSerializerDefinition> config, string value)
    {
        var settingsHolder = config.GetSettings();
        settingsHolder.Set(MyCustomSerializerDefinition.Key, value);
    }
}

Register the serializer

To use the customer serializer, it must be registered as part of the endpoint configuration:

// register serializer additionally configuring settings
var serialization = endpointConfiguration.UseSerialization<MyCustomSerializerDefinition>();
serialization.Settings("settingsValue");