elsa-workflows/elsa-core · error · ArgumentException

Label name cannot exceed

Error message

Label name cannot exceed {NameMaxLength} characters.

What it means

The Label entity validates its Name property on assignment: if the value exceeds NameMaxLength characters, the constructor/setter throws ArgumentException naming the offending property. NormalizedName is only set after validation succeeds, so invalid labels are never partially constructed.

Solutions

  1. Truncate or reject the name in application code before constructing/assigning: check name.Length against the max length.
  2. Enforce a max-length validation rule in the UI/input model so over-length names never reach the entity.
  3. If longer names must be supported, persist a custom entity or raise the limit via the applicable entity configuration rather than bypassing the check.

Example fix

// before
var label = new Label(userInputName); // throws when userInputName too long
// after
const int Max = Label.NameMaxLength;
var name = userInputName.Length > Max ? userInputName[..Max] : userInputName;
var label = new Label(name);
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrEmpty(name) && name.Length > Label.NameMaxLength)
    throw new ArgumentException($"Label name cannot exceed {Label.NameMaxLength} characters.", nameof(name));

Type guard

static bool IsValidLabelName(string? name) => !string.IsNullOrEmpty(name) && name.Length <= Label.NameMaxLength;

Try / catch

try { var label = new Label(name); }
catch (ArgumentException ex) when (ex.ParamName == nameof(Label.Name))
{
    modelState.AddModelError("Name", ex.Message);
}

Prevention

When it happens

Trigger: Constructing new Label(name) or setting label.Name with a string longer than the Label.NameMaxLength constant, e.g. free-form user input used directly as a label name.

Common situations: Importing labels from external systems with lax length limits, users typing very long label names in Studio, or mapping database rows containing over-length names into Label entities after a max-length reduction in a newer version.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at src/modules/Elsa.Labels/Entities/Label.cs:25

/// </summary>
public class Label : Entity
{
    /// <summary>
    /// Shared maximum for <see cref="Name"/> and <see cref="NormalizedName"/>.
    /// Matches the MySQL unique-index limit that every provider's schema must honor.
    /// </summary>
    public const int NameMaxLength = 255;

    private string _name = default!;

    public string Name
    {
        get => _name;
        set
        {
            if (value.Length > NameMaxLength)
            {
                throw new ArgumentException(
                    $"Label name cannot exceed {NameMaxLength} characters.",
                    nameof(Name));
            }

            _name = value;
            NormalizedName = value.ToLowerInvariant();
        }
    }

    public string NormalizedName { get; set; } = default!;
    public string? Description { get; set; }
    public string? Color { get; set; }
}

View on GitHub (pinned to fe9217bdfa)