Bond Serializer

NuGet Package NServiceBus.Bond (3.x) | License
This is a community maintained project. License and support are independent of Particular Software.
Target NServiceBus Version: 7.x

Serializes messages with Microsoft Bond.

Bond is a cross-platform framework for working with schematized data. It supports cross-language serialization/deserialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high-scale services.


This serializer does not support messages defined as interfaces. If an explicit interface is sent, an exception will be thrown with the following message:

Interface based message are not supported.
Create a class that implements the desired interface

Instead, use a public class with the same contract as the interface. The class can optionally implement any required interfaces.


Customizes the cached delegates that serialize and deserialize message types. This is an optional setting.

The default serialization delegates are as follows.

var serialization = endpointConfiguration.UseSerialization<BondSerializer>();
    serializationDelegatesBuilder: messageType =>
        var item = SerializerCache.GetSerializer(messageType);
        return new SerializationDelegates(
            serialize: (buffer, message) =>
                var writer = new CompactBinaryWriter<OutputBuffer>(buffer);
                item.Serializer.Serialize(message, writer);
            deserialize: buffer =>
                var reader = new CompactBinaryReader<InputBuffer>(buffer);
                return item.Deserializer.Deserialize(reader);

The serializers are cached as per the Bond performance guidance.

static class SerializerCache
    static ConcurrentDictionary<Type, Item> cache = new ConcurrentDictionary<Type, Item>();

    public static Item GetSerializer(Type messageType)
        return cache.GetOrAdd(messageType,
            type => new Item
                new Serializer<CompactBinaryWriter<OutputBuffer>>(type),
                new Deserializer<CompactBinaryReader<InputBuffer>>(type)

    public class Item
        public readonly Serializer<CompactBinaryWriter<OutputBuffer>> Serializer;
        public readonly Deserializer<CompactBinaryReader<InputBuffer>> Deserializer;

        public Item(
            Serializer<CompactBinaryWriter<OutputBuffer>> serializer,
            Deserializer<CompactBinaryReader<InputBuffer>> deserializer)
            Serializer = serializer;
            Deserializer = deserializer;

Custom content key

When using additional deserializers or transitioning between different versions of the same serializer it can be helpful to take explicit control over the content type a serializer passes to NServiceBus (to be used for the ContentType header).

var serialization = endpointConfiguration.UseSerialization<BondSerializer>();


Last modified