{"record":{"id":"a2ba3caacc23be63","repo":"MassTransit/MassTransit","slug":"the-saga-does-not-have-a-public-constructor-with-a-single","errorCode":null,"errorMessage":"The saga does not have a public constructor with a single Guid correlationId parameter: ","messagePattern":"The saga does not have a public constructor with a single Guid correlationId parameter: ","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/MassTransit/Sagas/Configuration/ConstructorSagaInstanceFactory.cs","lineNumber":22,"sourceCode":"    using System.Linq.Expressions;\n    using Internals;\n    using Saga;\n\n\n    /// <summary>\n    /// Creates a saga instance using the constructor, via a compiled expression. This class\n    /// is built asynchronously and hot-wrapped to replace the basic Activator style.\n    /// </summary>\n    /// <typeparam name=\"TSaga\"></typeparam>\n    public class ConstructorSagaInstanceFactory<TSaga>\n        where TSaga : class, ISaga\n    {\n        public ConstructorSagaInstanceFactory()\n        {\n            var constructorInfo = typeof(TSaga).GetConstructor(new[] { typeof(Guid) });\n            if (constructorInfo == null)\n            {\n                throw new ArgumentException(\"The saga does not have a public constructor with a single Guid correlationId parameter: \"\n                    + TypeCache<TSaga>.ShortName);\n            }\n\n            var correlationId = Expression.Parameter(typeof(Guid), \"correlationId\");\n            var @new = Expression.New(constructorInfo, correlationId);\n\n            FactoryMethod = Expression.Lambda<SagaInstanceFactoryMethod<TSaga>>(@new, correlationId).CompileFast();\n        }\n\n        public SagaInstanceFactoryMethod<TSaga> FactoryMethod { get; }\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":35,"githubUrl":"https://github.com/MassTransit/MassTransit/blob/62ab339afa3bac2e9b3fe1769d0d35d7e44778e9/src/MassTransit/Sagas/Configuration/ConstructorSagaInstanceFactory.cs#L4-L35","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add a public constructor to the saga taking a single Guid: public MySaga(Guid correlationId).","Alternatively use a factory that matches your saga's shape (e.g. PropertySagaInstanceFactory with a parameterless constructor and writable CorrelationId).","Provide a custom ISagaInstanceFactory/ISagaFactory implementation for the saga."],"exampleFix":"// before\npublic class OrderSaga :\n    ISaga\n{\n    public OrderSaga() { }\n    public Guid CorrelationId { get; private set; }\n}\n\n// after\npublic class OrderSaga :\n    ISaga\n{\n    public OrderSaga(Guid correlationId)\n    {\n        CorrelationId = correlationId;\n    }\n    public Guid CorrelationId { get; private set; }\n}","handlingStrategy":"validation","validationCode":"// before configuring the saga\nif (typeof(OrderSaga).GetConstructor(new[] { typeof(Guid) }) == null)\n    throw new InvalidOperationException(\"OrderSaga must expose a public constructor taking a single Guid correlationId\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always give sagas a public constructor with a single Guid parameter when using the default factory.","Write a unit test that instantiates each saga type with new T(Guid.NewGuid()).","Keep saga configuration close to the saga class so constructor requirements are visible during review."],"tags":["saga","reflection","configuration","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"62ab339afa3bac2e9b3fe1769d0d35d7e44778e9","analyzedAt":"2026-09-13T22:47:47.593Z","contentChangedAt":"2026-09-13T22:47:47.593Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}