OrchardCMS/OrchardCore · error · NotImplementedException
Comparing to is currently not implemented.
Error message
Comparing {objA?.GetType()} to {objB?.GetType()} is currently not implemented. What it means
This NotImplementedException is thrown by JsonDynamicValue.Compare (used by CompareTo and sorting) when both objects are not one of the supported type combinations (numbers, strings, booleans, etc.). The switch default means the pair of runtime types has no comparison rule implemented.
Solutions
- Normalize/sort values in your own code by converting to string or number first
- Filter out non-comparable (object/array/null) values before sorting
- Only compare values of the same JSON kind (numbers with numbers, strings with strings)
- Extend wrapping logic to project mixed values to a common type
Example fix
// before array.OrderBy(x => x.OrderByField) // mixed kinds throw // after array.OrderBy(x => x.OrderByField?.GetObjectValue()?.ToString(), StringComparer.Ordinal)
Defensive patterns
Strategy: type-guard
Validate before calling
static bool IsSortable(object? v) => v is not null &&
v.GetPropertyValue() is JsonElement el &&
el.ValueKind is JsonValueKind.Number or JsonValueKind.String; Type guard
static bool IsComparableKind(JsonDynamicValue? v) =>
v?.GetObjectValue() is JsonElement el &&
el.ValueKind is JsonValueKind.Number or JsonValueKind.String; Try / catch
int cmp;
try { cmp = a.CompareTo(b); }
catch (NotImplementedException ex) { /* log, fallback to string compare */
cmp = string.CompareOrdinal(a?.ToString(), b?.ToString()); } Prevention
- Only sort/order JSON values of the same kind (all numbers or all strings)
- Filter out objects/arrays/null before ordering
- Project mixed-type fields to a normalized string or double in your own code
- Write tests covering the actual field-type distribution of your data
When it happens
Trigger: Calling CompareTo or sorting/ordering JsonDynamicValue instances whose underlying values are of an unsupported type combination, e.g. comparing an object or array to anything, or a boolean to a string.
Common situations: Sorting mixed-type JSON arrays (e.g. JArray with [1, "a", true]); ordering search results where a field varies in type across documents; comparing nested JSON objects for ordering.
Related errors
- A duplicate key ' ' was found.
- Can't use the non numeric key
- Can't use the numeric key
- Cannot convert to
- Cannot convert to BigInteger.
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/437c16f1f681946c.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs:737
var d1 = Convert.ToDouble(objA, CultureInfo.InvariantCulture);
var d2 = Convert.ToDouble(objB, CultureInfo.InvariantCulture);
return d1.CompareTo(d2);
}
else
{
return Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture));
}
case JsonValueKind.String:
var s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);
var s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);
return string.CompareOrdinal(s1, s2);
default:
throw new NotImplementedException($"Comparing {objA?.GetType()} to {objB?.GetType()} is currently not implemented.");
}
}
private static int CompareBigInteger(BigInteger i1, object i2)
{
var result = i1.CompareTo(ToBigInteger(i2));
if (result != 0)
{
return result;
}
// Converting a fractional number to a BigInteger will lose the fraction
// check for fraction if result is two numbers are equal
if (i2 is decimal d1)
{
return (0m).CompareTo(Math.Abs(d1 - Math.Truncate(d1)));
}View on GitHub (pinned to 4306c0717f)