MassTransit/MassTransit · error · SerializationException

An Activity Name is required

Error message

An Activity Name is required

What it means

When deserializing a RoutingSlip, RoutingSlipActivity's constructor validates the source Activity. If Activity.Name is null or empty it throws SerializationException — a routing slip activity without a name cannot be routed or tracked, so the message is treated as corrupt.

Solutions

  1. Fix the producer so every Activity added to the routing slip has a non-empty Name (AddActivity/Execute with a named activity)
  2. Reject/quarantine malformed routing slip messages and log the message id for diagnosis
  3. Validate routing slip payloads after deserialization from external/untrusted sources

Example fix

// before
var activity = new Activity(); // Name not set
routingSlipBuilder.AddActivity(activity);
// after
var activity = new Activity("ProcessOrder")
{
    Address = new Uri("queue:process-order")
};
routingSlipBuilder.AddActivity(activity);
Defensive patterns

Strategy: try-catch

Validate before calling

if (string.IsNullOrEmpty(activity?.Name))
    throw new InvalidOperationException("Routing slip activity requires a Name before use");

Type guard

bool IsValidActivity(Activity? a) => a != null && !string.IsNullOrEmpty(a.Name) && a.Address != null;

Try / catch

try { var ra = new RoutingSlipActivity(activity); }
catch (SerializationException ex) { logger.LogError(ex, "Malformed routing slip activity: {Message}", ex.Message); return; }

Prevention

When it happens

Trigger: Deserializing a routing slip message whose activities array contains an entry with a missing/empty Name — usually from a hand-built routing slip, a serialized form produced by another version, or manual JSON editing.

Common situations: Building routing slips with an activity whose Name was never set; schema drift between MassTransit versions or between producer/consumer; corrupted or hand-edited routing slip payloads on the wire.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/MassTransit.Abstractions/Courier/Courier/Messages/RoutingSlipActivity.cs:31

    {
    #pragma warning disable CS8618
        public RoutingSlipActivity()
    #pragma warning restore CS8618
        {
        }

        public RoutingSlipActivity(string name, Uri address, IDictionary<string, object> arguments)
        {
            Name = name;
            Address = address;
            Arguments = arguments;
        }

        [SuppressMessage("ReSharper", "ConstantNullCoalescingCondition")]
        public RoutingSlipActivity(Activity activity)
        {
            if (string.IsNullOrEmpty(activity.Name))
                throw new SerializationException("An Activity Name is required");
            if (activity.Address == null)
                throw new SerializationException("An Activity ExecuteAddress is required");

            Name = activity.Name;
            Address = activity.Address;
            Arguments = activity.Arguments ?? new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        }

        public string Name { get; set; }
        public Uri Address { get; set; }
        public IDictionary<string, object> Arguments { get; set; }
    }
}

View on GitHub (pinned to 62ab339afa)