MassTransit/MassTransit · error · ArgumentException

The saga does not have a public constructor with a single Gu

Error message

The saga does not have a public constructor with a single Guid correlationId parameter: 

What it means

ConstructorSagaInstanceFactory is the default saga instance factory for saga types used with the default (correlationId constructor) pattern. At construction it reflects over typeof(TSaga) looking for a public constructor taking a single Guid parameter; if none exists it throws ArgumentException immediately when the saga is configured. This ensures new saga instances can be created from a message's CorrelationId.

Solutions

  1. Add a public constructor to the saga taking a single Guid: public MySaga(Guid correlationId).
  2. Alternatively use a factory that matches your saga's shape (e.g. PropertySagaInstanceFactory with a parameterless constructor and writable CorrelationId).
  3. Provide a custom ISagaInstanceFactory/ISagaFactory implementation for the saga.

Example fix

// before
public class OrderSaga :
    ISaga
{
    public OrderSaga() { }
    public Guid CorrelationId { get; private set; }
}

// after
public class OrderSaga :
    ISaga
{
    public OrderSaga(Guid correlationId)
    {
        CorrelationId = correlationId;
    }
    public Guid CorrelationId { get; private set; }
}
Defensive patterns

Strategy: validation

Validate before calling

// before configuring the saga
if (typeof(OrderSaga).GetConstructor(new[] { typeof(Guid) }) == null)
    throw new InvalidOperationException("OrderSaga must expose a public constructor taking a single Guid correlationId");

Prevention

When it happens

Trigger: Configuring a saga (e.g. sagaRepository / saga configuration using ConstructorSagaInstanceFactory) where TSaga has no public constructor with signature Ctor(Guid correlationId). Thrown in the factory constructor, i.e. at endpoint/receive configuration time, not at message time.

Common situations: Saga class only has a parameterless constructor or constructors taking other types (state object, context); saga uses property-based correlation instead; constructor is internal/private; wrong generic type passed to configuration.

Related errors


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

Appendix: source

Thrown at src/MassTransit/Sagas/Configuration/ConstructorSagaInstanceFactory.cs:22

    using System.Linq.Expressions;
    using Internals;
    using Saga;


    /// <summary>
    /// Creates a saga instance using the constructor, via a compiled expression. This class
    /// is built asynchronously and hot-wrapped to replace the basic Activator style.
    /// </summary>
    /// <typeparam name="TSaga"></typeparam>
    public class ConstructorSagaInstanceFactory<TSaga>
        where TSaga : class, ISaga
    {
        public ConstructorSagaInstanceFactory()
        {
            var constructorInfo = typeof(TSaga).GetConstructor(new[] { typeof(Guid) });
            if (constructorInfo == null)
            {
                throw new ArgumentException("The saga does not have a public constructor with a single Guid correlationId parameter: "
                    + TypeCache<TSaga>.ShortName);
            }

            var correlationId = Expression.Parameter(typeof(Guid), "correlationId");
            var @new = Expression.New(constructorInfo, correlationId);

            FactoryMethod = Expression.Lambda<SagaInstanceFactoryMethod<TSaga>>(@new, correlationId).CompileFast();
        }

        public SagaInstanceFactoryMethod<TSaga> FactoryMethod { get; }
    }
}

View on GitHub (pinned to 62ab339afa)