{"record":{"id":"437c16f1f681946c","repo":"OrchardCMS/OrchardCore","slug":"comparing-obja-gettype-to-objb-gettype-is-currently-not","errorCode":null,"errorMessage":"Comparing {objA?.GetType()} to {objB?.GetType()} is currently not implemented.","messagePattern":"Comparing (.+?) to (.+?) is currently not implemented\\.","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs","lineNumber":737,"sourceCode":"                    var d1 = Convert.ToDouble(objA, CultureInfo.InvariantCulture);\n                    var d2 = Convert.ToDouble(objB, CultureInfo.InvariantCulture);\n\n                    return d1.CompareTo(d2);\n                }\n                else\n                {\n                    return Convert.ToInt64(objA, CultureInfo.InvariantCulture).CompareTo(Convert.ToInt64(objB, CultureInfo.InvariantCulture));\n                }\n\n            case JsonValueKind.String:\n\n                var s1 = Convert.ToString(objA, CultureInfo.InvariantCulture);\n                var s2 = Convert.ToString(objB, CultureInfo.InvariantCulture);\n\n                return string.CompareOrdinal(s1, s2);\n\n            default:\n                throw new NotImplementedException($\"Comparing {objA?.GetType()} to {objB?.GetType()} is currently not implemented.\");\n        }\n    }\n\n    private static int CompareBigInteger(BigInteger i1, object i2)\n    {\n        var result = i1.CompareTo(ToBigInteger(i2));\n\n        if (result != 0)\n        {\n            return result;\n        }\n\n        // Converting a fractional number to a BigInteger will lose the fraction\n        // check for fraction if result is two numbers are equal\n        if (i2 is decimal d1)\n        {\n            return (0m).CompareTo(Math.Abs(d1 - Math.Truncate(d1)));\n        }","sourceCodeStart":719,"sourceCodeEnd":755,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.Abstractions/Json/Dynamic/JsonDynamicValue.cs#L719-L755","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\narray.OrderBy(x => x.OrderByField) // mixed kinds throw\n// after\narray.OrderBy(x => x.OrderByField?.GetObjectValue()?.ToString(), StringComparer.Ordinal)","handlingStrategy":"type-guard","validationCode":"static bool IsSortable(object? v) => v is not null &&\n    v.GetPropertyValue() is JsonElement el &&\n    el.ValueKind is JsonValueKind.Number or JsonValueKind.String;","typeGuard":"static bool IsComparableKind(JsonDynamicValue? v) =>\n    v?.GetObjectValue() is JsonElement el &&\n    el.ValueKind is JsonValueKind.Number or JsonValueKind.String;","tryCatchPattern":"int cmp;\ntry { cmp = a.CompareTo(b); }\ncatch (NotImplementedException ex) { /* log, fallback to string compare */\n    cmp = string.CompareOrdinal(a?.ToString(), b?.ToString()); }","preventionTips":["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"],"tags":["not-implemented","json","comparison","sorting"],"backgroundTag":"method-not-implemented","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}