OrchardCMS/OrchardCore · error · ArgumentException

Invalid range query

Error message

Invalid range query

What it means

This is RangeFilterProvider.CreateFilteredQuery's outer default switch branch. The range filter's overall value was neither an object (holding gt/gte/lt/lte bounds) nor the other handled node kind, so no range query could be constructed and the provider throws ArgumentException("Invalid range query").

Solutions

  1. Express bounds as an object: {"range": {"Price": {"gte": 1, "lte": 10}}}.
  2. Omit unused bounds instead of substituting arrays or scalars for them.
  3. Validate that every range filter's value is a JSON object before executing the query.
  4. Check recipes/saved queries for range filters whose object value was flattened during editing or migration.

Example fix

// before
{"range": {"Price": [1, 10]}}
// after
{"range": {"Price": {"gte": 1, "lte": 10}}}
Defensive patterns

Strategy: validation

Validate before calling

if (filter.TryGetPropertyValue(field, out var v) && v.ValueKind != JsonValueKind.Object)
{
    throw new InvalidOperationException(
        $"range filter for '{field}' must be an object of gt/gte/lt/lte bounds, got {v.ValueKind}.");
}

Type guard

static bool IsRangeObject(JsonElement v) => v.ValueKind == JsonValueKind.Object;

Try / catch

try
{
    var query = provider.CreateFilteredQuery(context);
}
catch (ArgumentException ex) when (ex.Message.Contains("Invalid range"))
{
    _logger.LogError(ex, "Range filter value is not an object: {Json}", filterJson);
    throw new QueryValidationException("range filters require an object with bounds.", ex);
}

Prevention

When it happens

Trigger: Calling CreateFilteredQuery with {"range": {"Price": 42}} or {"range": {"Price": [1, 10]}} — a scalar or array value where an object with bounds (gt/gte/lt/lte) is required, so the outer switch falls to default.

Common situations: Writing bounds as a tuple-style array out of habit from other query DSLs; a serialized filter losing its nested object during JSON round-tripping; hand-edited saved queries where the bounds object was accidentally deleted.

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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/RangeFilterProvider.cs:106

                        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;
                }

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

        booleanQuery.Add(rangeQuery, Occur.MUST);
        var queryFilter = new QueryWrapperFilter(rangeQuery);

        return new FilteredQuery(booleanQuery, queryFilter);
    }
}

View on GitHub (pinned to 4306c0717f)