OrchardCMS/OrchardCore · error · ArgumentException
Invalid prefix query
Error message
Invalid prefix query
What it means
This is PrefixFilterProvider.CreateFilteredQuery's default switch branch. The prefix filter's value was neither an object (with a "prefix" property) nor the other handled value kind, so no PrefixQuery could be built and the provider throws ArgumentException("Invalid prefix query").
Solutions
- Wrap the prefix in an object: {"prefix": {"Title": {"prefix": "Orch"}}}.
- Ensure the value's JSON kind is one the provider handles (object with "prefix", or string) before calling CreateFilteredQuery.
- Search saved queries/recipes for prefix filters with non-object values and fix them.
- Log the raw filter JSON in a try/catch around CreateFilteredQuery to find the malformed node.
Example fix
// before
{"prefix": {"Title": 123}}
// after
{"prefix": {"Title": {"prefix": "123"}}} Defensive patterns
Strategy: validation
Validate before calling
if (filter.TryGetPropertyValue(field, out var v) &&
v.ValueKind is not (JsonValueKind.String or JsonValueKind.Object))
{
throw new InvalidOperationException(
$"prefix value for '{field}' must be a string or object, got {v.ValueKind}.");
} Type guard
static bool IsValidPrefixValue(JsonElement v) =>
v.ValueKind is JsonValueKind.String or JsonValueKind.Object; Try / catch
try
{
var query = provider.CreateFilteredQuery(context);
}
catch (ArgumentException ex) when (ex.Message.Contains("Invalid prefix"))
{
_logger.LogError(ex, "Unsupported prefix value kind: {Json}", filterJson);
throw new QueryValidationException("prefix filters require string or object values.", ex);
} Prevention
- Pass the prefix as an object {"prefix": ...} or a plain string, never a number/bool/null.
- Audit saved queries for prefix filters with scalar values after version upgrades.
- Build filter JSON through typed helpers instead of string concatenation.
When it happens
Trigger: Passing {"prefix": {"Title": 123}} or {"prefix": {"Title": true}} or {"prefix": {"Title": null}} — a scalar/null value where an object (or the accepted simple form) is expected, causing the value-kind switch to fall to default.
Common situations: Query JSON generated by code that serializes numbers/booleans as-is; copying a wildcard-style filter definition into a prefix filter; a saved query written against an older syntax that no longer parses in the current Orchard Core version.
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
- Invalid query
- Invalid wildcard query
- Missing value in match phrase query
- Prefix query misses prefix value
- Invalid range query
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/74963c1213abb67a.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/Filters/PrefixFilterProvider.cs:55
{
prefixQuery = new PrefixQuery(new Term(first.Key, value.Value<string>()));
}
else if (obj.TryGetPropertyValue("prefix", out var prefix))
{
prefixQuery = new PrefixQuery(new Term(first.Key, prefix.Value<string>()));
}
else
{
throw new ArgumentException("Prefix query misses prefix value");
}
if (obj.TryGetPropertyValue("boost", out var boost))
{
prefixQuery.Boost = boost.Value<float>();
}
break;
default: throw new ArgumentException("Invalid prefix query");
}
booleanQuery.Add(prefixQuery, Occur.MUST);
var queryFilter = new QueryWrapperFilter(prefixQuery);
return new FilteredQuery(booleanQuery, queryFilter);
}
}
View on GitHub (pinned to 4306c0717f)