OrchardCMS/OrchardCore · error · ArgumentException

Invalid range query

Error message

Invalid range query

What it means

RangeQueryProvider.CreateQuery only recognizes a JSON object node (containing type 'range' with gt/gte/lt/lte). If the node kind for a range query is anything other than Object, the outer switch's default throws ArgumentException. Like the prefix provider, this enforces that range queries are described by objects.

Solutions

  1. Provide a proper object: {"field": {"type": "range", "gt": ..., "lt": ...}}.
  2. Check the query JSON actually stored/passed — a plain value indicates the range object was flattened or dropped.
  3. Fix the producer code (e.g. the query builder) to emit the object form for range queries.

Example fix

// before
{"CreatedUtc": "2023-01-01"}
// after
{"CreatedUtc": {"type": "range", "gte": "2023-01-01", "lt": "2024-01-01"}}
Defensive patterns

Strategy: type-guard

Validate before calling

if (node?.GetValueKind() == JsonValueKind.Object) { /* safe to call */ }

Type guard

static bool IsRangeQueryObject(JsonNode node) => node is JsonObject o && o.TryGetPropertyValue("type", out var t) && t.GetValueKind() == JsonValueKind.String && t.GetValue<string>() == "range";

Try / catch

try { var q = provider.CreateQuery(node); } catch (ArgumentException ex) when (ex.Message == "Invalid range query") { // log raw query JSON and show a schema hint }

Prevention

When it happens

Trigger: Passing {"field": "someString"} or an array node to a query intended as a range query, so nodeKind != JsonValueKind.Object.

Common situations: Query JSON where the range object was lost during serialization; mixing up term and range syntax; programmatic query builders emitting the wrong structure.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/317e4cba0c1846e8. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/RangeQueryProvider.cs:98

                        }

                        break;

                    case JsonValueKind.String:
                        var minString = gt?.Value<string>();
                        var maxString = lt?.Value<string>();
                        rangeQuery = TermRangeQuery.NewStringRange(field, minString, maxString, includeLower, includeUpper);
                        break;
                    default: throw new ArgumentException($"Unsupported range value type: {type}");
                }

                if (boost != null)
                {
                    rangeQuery.Boost = boost.Value;
                }

                return rangeQuery;
            default: throw new ArgumentException("Invalid range query");
        }
    }
}

View on GitHub (pinned to 4306c0717f)