{"record":{"id":"80a524ab082cb780","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-o-gettype-typeof","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(FlowNode))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, o\\.GetType\\(\\), typeof\\(FlowNode\\)\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowNode.cs","lineNumber":113,"sourceCode":"            Debug.Assert(_fp != fn._fp || (_fp == fn._fp) && (_scopeId == fn._scopeId));\n\n            return (this._fp == fn._fp);\n        }\n\n\n        /// <summary>\n        /// Compare the flow order of this FlowNode to another FlowNode\n        /// </summary>\n        /// <param name=\"o\">FlowNode to compare to</param>\n        /// <returns>-1, 0, 1</returns>\n        public int CompareTo(object o)\n        {\n            ArgumentNullException.ThrowIfNull(o);\n\n            FlowNode fp = o as FlowNode;\n            if (fp == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(FlowNode)), nameof(o));\n            }\n\n            if (Object.ReferenceEquals(this, fp))\n            {\n                return 0;\n            }\n\n            int fd = this._fp - fp._fp;\n            if (fd == 0)\n            {\n                return 0;\n            }\n            else if (fd < 0)\n            {\n                return -1;\n            }\n            else\n            {","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowNode.cs#L95-L131","documentation":"FlowNode.CompareTo throws ArgumentException when the object passed for comparison is not a FlowNode. WPF's flow document layout uses FlowNode comparison internally to order content nodes; passing any other type violates the IComparable contract this method implements.","triggerScenarios":"Calling FlowNode.CompareTo(obj) directly (or via a sort/compare delegate) with an object of a type other than FlowNode; null is separately rejected with ArgumentNullException.","commonSituations":"Custom sorting or binary-search code over mixed-type collections that include FlowNodes; reflection-based tooling or third-party code that calls IComparable without checking the concrete type first.","solutions":["Ensure every element compared against a FlowNode is actually a FlowNode instance","Use 'is FlowNode' pattern matching to filter before comparing","Sort within strongly typed List<FlowNode> collections rather than heterogeneous lists"],"exampleFix":"// before\nint r = flowNode.CompareTo(otherObject);\n// after\nint r = otherObject is FlowNode fn ? flowNode.CompareTo(fn) : throw new InvalidOperationException(\"not a FlowNode\");","handlingStrategy":"type-guard","validationCode":"if (obj is FlowNode fn) { result = node.CompareTo(fn); }","typeGuard":"static bool IsFlowNode(object o) => o is FlowNode;","tryCatchPattern":"try { node.CompareTo(o); } catch (ArgumentException ex) when (ex.ParamName == \"o\") { /* handle wrong type */ }","preventionTips":["Use List<FlowNode> instead of ArrayList/object lists","Type-check before IComparable calls","Prefer Comparer<FlowNode>.Default"],"tags":["wpf","icomparable","argumentexception"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}