elsa-workflows/elsa-core · error · KeyNotFoundException

None of the specified keys were found

Error message

None of the specified keys were found: {string.Join(", ", names)}

What it means

JsonElementExtensions.GetProperty(element, params string[] names) returns the first matching property among the candidate names and throws KeyNotFoundException when none of them exist on the JSON element. It is a convenience lookup for tolerant JSON property access in Elsa. Since JsonElement has no such multi-key lookup natively, Elsa throws rather than returning default.

Solutions

  1. Confirm the actual JSON keys at runtime (e.g. log element.ToString()) and pass the correct name
  2. Add the alternate key names to the params list, or use element.TryGetProperty before calling
  3. Guard with a custom helper that returns a default value instead of throwing
  4. Validate the payload schema before parsing

Example fix

// before
var status = doc.RootElement.GetProperty("state", "status");
// after
var status = doc.RootElement.TryGetProperty("state", out var el) ? el.GetString() : null;
Defensive patterns

Strategy: type-guard

Validate before calling

bool HasAny(JsonElement el, params string[] names) => names.Any(n => el.ValueKind == JsonValueKind.Object && el.TryGetProperty(n, out _));

Type guard

bool TryGetString(JsonElement el, out string? value, params string[] names) { foreach (var n in names) if (el.TryGetProperty(n, out var v) && v.ValueKind == JsonValueKind.String) { value = v.GetString(); return true; } value = null; return false; }

Try / catch

try { prop = element.GetProperty("state", "status"); } catch (KeyNotFoundException) { prop = default; }

Prevention

When it happens

Trigger: Calling element.GetProperty("state", "status") on a JSON payload that contains neither key; parsing a webhook/API payload whose schema differs from expected (e.g. wrong casing, renamed field, empty object).

Common situations: Third-party API changed its response schema; deserializing with wrong casing options; accessing a property on an empty or array JsonElement; consuming a payload from a different event/version.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at src/modules/Elsa.Workflows.Core/Extensions/JsonElementExtensions.cs:17

using System.Text.Json;

// ReSharper disable once CheckNamespace
namespace Elsa.Extensions;

public static class JsonElementExtensions
{
    /// <summary>
    /// Returns a child element where its name matches any of the specified names.
    /// </summary>
    public static JsonElement GetProperty(this JsonElement element, params string[] names)
    {
        foreach (var name in names)
            if (element.TryGetProperty(name, out var value))
                return value;

        throw new KeyNotFoundException($"None of the specified keys were found: {string.Join(", ", names)}");
    }
}

View on GitHub (pinned to fe9217bdfa)