elsa-workflows/elsa-core · error · ArgumentOutOfRangeException

Unsupported persistence column type.

Error message

Unsupported persistence column type.

What it means

SqlServerTypeMapper.Map translates a PersistenceColumnType to a SQL Server type string via a switch expression. The default arm throws ArgumentOutOfRangeException with the column type when a PersistenceColumnType value has no SQL Server mapping, meaning the mapper and the column-type enum are out of sync (a new enum member was added without updating this mapper).

Solutions

  1. Align package versions so Elsa.Persistence.VNext.SqlServer matches the abstractions package that defines PersistenceColumnType.
  2. Add a mapping arm for the new PersistenceColumnType member in SqlServerTypeMapper.Map.
  3. Verify the column's Type was set correctly upstream (default(enum) or an unmapped custom value will land in the default arm).

Example fix

// before
_ => throw new ArgumentOutOfRangeException(nameof(column), column.Type, "Unsupported persistence column type.")
// after
PersistenceColumnType.Guid => "uniqueidentifier",
PersistenceColumnType.Decimal => "decimal(38, 10)",
_ => throw new ArgumentOutOfRangeException(nameof(column), column.Type, "Unsupported persistence column type.")
Defensive patterns

Strategy: type-guard

Validate before calling

static readonly HashSet<PersistenceColumnType> Mapped =
    new() { Int32, Int64, Boolean, DateTimeOffset, Text, Json, String };
if (!Mapped.Contains(column.Type))
    throw new NotSupportedException($"{column.Type} has no SQL Server mapping.");

Type guard

bool IsMappable(PersistenceColumnType type) => type is
    PersistenceColumnType.Int32 or PersistenceColumnType.Int64 or
    PersistenceColumnType.Boolean or PersistenceColumnType.DateTimeOffset or
    PersistenceColumnType.Text or PersistenceColumnType.Json or PersistenceColumnType.String;

Try / catch

try { var sqlType = mapper.Map(column); }
catch (ArgumentOutOfRangeException ex) { logger.LogError(ex, "Unmapped column type {Type}", ex.ActualValue); }

Prevention

When it happens

Trigger: Schema generation encounters a PersistenceColumnType value not covered by the switch (e.g. a newly added enum member like Guid/Decimal not yet mapped), typically after upgrading the persistence abstractions package while the SqlServer provider is older, or passing a column with an invalid/default enum value.

Common situations: Mixed package versions after a partial upgrade (abstractions newer than the SqlServer provider); custom column types contributed by an extension; a bug where column.Type was never assigned.

Related errors


AI-assisted analysis of elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/7c526292bab9cebf. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Persistence.VNext.SqlServer/SqlServerTypeMapper.cs:17

using Elsa.Persistence.VNext.Relational;

namespace Elsa.Persistence.VNext.SqlServer;

public class SqlServerTypeMapper : IRelationalTypeMapper
{
    public string Map(PersistenceColumn column)
    {
        return column.Type switch
        {
            PersistenceColumnType.Int32 => "int",
            PersistenceColumnType.Int64 => "bigint",
            PersistenceColumnType.Boolean => "bit",
            PersistenceColumnType.DateTimeOffset => "datetimeoffset",
            PersistenceColumnType.Text or PersistenceColumnType.Json => "nvarchar(max)",
            PersistenceColumnType.String => column.Length is { } length ? $"nvarchar({length})" : "nvarchar(max)",
            _ => throw new ArgumentOutOfRangeException(nameof(column), column.Type, "Unsupported persistence column type.")
        };
    }
}

View on GitHub (pinned to fe9217bdfa)