MassTransit/MassTransit · error · ConfigurationException

No JSON serializer configured

Error message

No JSON serializer configured

What it means

ObjectDeserializer.Serialize resolves a lazily configured JSON serializer (per AsyncLocal current, else static _serializer). If neither is set, it throws ConfigurationException — no serializer was configured on the bus/serialization configuration before this static helper was used.

Solutions

  1. Configure MassTransit's JSON serializer before calling ObjectDeserializer (set up the bus / serializer options during startup)
  2. Ensure bus configuration (e.g. cfg.UseSerialization / serializer registration) executes before any Serialize call
  3. In tests, initialize serialization in a fixture setup step
  4. If you only need ad-hoc JSON, use JsonSerializer.Serialize directly instead of ObjectDeserializer

Example fix

// before
var json = ObjectDeserializer.Serialize(msg); // no serializer configured -> throws
// after
cfg.UseSerialization(SystemTextJsonSerializerFactory.Default); // during bus config
var json = ObjectDeserializer.Serialize(msg);
Defensive patterns

Strategy: try-catch

Validate before calling

if (ObjectDeserializer.Current == null) // or check serializer configured during startup
    throw new InvalidOperationException("Call bus/serialization configuration before ObjectDeserializer.Serialize");

Type guard

null

Try / catch

try { return ObjectDeserializer.Serialize(value); }
catch (ConfigurationException ex) { logger.LogCritical(ex, "MassTransit JSON serializer not configured"); throw; }

Prevention

When it happens

Trigger: Calling ObjectDeserializer.Serialize(object) before any MassTransit JSON serializer has been configured (e.g. before bus creation / JsonSerializerOptions registration), typically at startup or in code paths that run outside a configured bus.

Common situations: Unit tests that call ObjectDeserializer directly without configuring MassTransit serialization; using the static helper in a console app before BusConfigurator runs; ordering bugs where serialization happens before AddMassTransit completes.

Related errors


AI-assisted analysis of MassTransit/MassTransit@62ab339afa (2026-09-13). Data as JSON: /api/errors/dbd8621e2788a380. Report an issue: GitHub.

Appendix: source

Thrown at src/MassTransit/Serialization/ObjectDeserializer.cs:28

        static readonly AsyncLocal<IObjectDeserializer?> _currentSerializer = new AsyncLocal<IObjectDeserializer?>();

        public static IObjectDeserializer? Default
        {
            set => _serializer = value ?? SystemTextJsonMessageSerializer.Instance;
        }

        public static IObjectDeserializer Current
        {
            set => _currentSerializer.Value = value;
        }

        public static string? Serialize(object? value)
        {
            if (value == null)
                return null;

            var serializer = _currentSerializer.Value ?? _serializer ?? throw new ConfigurationException("No JSON serializer configured");

            return serializer.SerializeObject(value).GetString();
        }

        public static T? Deserialize<T>(object? value, T? defaultValue = null)
            where T : class
        {
            switch (value)
            {
                case null:
                case string text when string.IsNullOrWhiteSpace(text):
                    return defaultValue;
            }

            var serializer = _currentSerializer.Value ?? _serializer ?? throw new ConfigurationException("No JSON serializer configured");

            return serializer.DeserializeObject<T>(value);
        }

View on GitHub (pinned to 62ab339afa)