elsa-workflows/elsa-core · error · InvalidOperationException

Elsa Platform maximum artifact size must be between 1 byte…

Error message

Elsa Platform maximum artifact size must be between 1 byte and the maximum runtime buffer size.

What it means

MaxArtifactBytes caps the size of command artifacts this runtime will download from the Platform. Validate() requires a value between 1 and Array.MaxLength, protecting the runtime buffer from oversized payloads.

Solutions

  1. Set MaxArtifactBytes to a sane positive limit, e.g. 10 * 1024 * 1024 (10 MB).
  2. Fix the bound configuration value so it parses to a positive integer.
  3. Cap the configured value: Math.Min(configured, Array.MaxLength).

Example fix

// before
options.MaxArtifactBytes = 0;
// after
options.MaxArtifactBytes = 10 * 1024 * 1024;
Defensive patterns

Strategy: validation

Validate before calling

if (options.Enabled && (options.MaxArtifactBytes <= 0 || options.MaxArtifactBytes > Array.MaxLength))
    options.MaxArtifactBytes = 10 * 1024 * 1024;

Try / catch

try { options.Validate(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("maximum artifact size"))
{
    logger.LogError(ex, "MaxArtifactBytes must be between 1 and Array.MaxLength.");
}

Prevention

When it happens

Trigger: Enabled = true plus Validate() with MaxArtifactBytes <= 0 or > Array.MaxLength.

Common situations: Config value bound to 0 or negative from a bad appsettings entry; someone set int.MaxValue * 2 or long.MaxValue; forgetting to set the value when all other options are configured manually.

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/5f15cfd63fe79a0f. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Platform.Integration/Options/ElsaPlatformIntegrationOptions.cs:49

        if (!Enabled)
            return;

        if (PlatformEndpoint is null)
            throw new InvalidOperationException("Elsa Platform endpoint is required when Platform integration is enabled.");
        if (WorkspaceId == Guid.Empty)
            throw new InvalidOperationException("Elsa Platform workspace ID is required when Platform integration is enabled.");
        if (EngineId == Guid.Empty)
            throw new InvalidOperationException("Elsa Platform engine ID is required when Platform integration is enabled.");
        if (string.IsNullOrWhiteSpace(EngineSecret))
            throw new InvalidOperationException("Elsa Platform engine secret is required when Platform integration is enabled.");
        if (string.IsNullOrWhiteSpace(WorkerId))
            throw new InvalidOperationException("Elsa Platform worker ID is required when Platform integration is enabled.");
        if (PollInterval <= TimeSpan.Zero)
            throw new InvalidOperationException("Elsa Platform poll interval must be positive.");
        if (ClaimLeaseDuration < TimeSpan.FromSeconds(1) || ClaimLeaseDuration.TotalSeconds > int.MaxValue)
            throw new InvalidOperationException("Elsa Platform claim lease duration must be between 1 second and the maximum supported Platform lease.");
        if (MaxArtifactBytes <= 0 || MaxArtifactBytes > Array.MaxLength)
            throw new InvalidOperationException("Elsa Platform maximum artifact size must be between 1 byte and the maximum runtime buffer size.");
        if (string.IsNullOrWhiteSpace(ShellOverlayPath))
            throw new InvalidOperationException("Elsa Platform shell overlay path is required when Platform integration is enabled.");
    }
}

View on GitHub (pinned to fe9217bdfa)