{"record":{"id":"c0d8b9b191da6377","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedparametertype-o-gettype-typeof-c0d8b9","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(FlowPosition))","messagePattern":"SR\\.Format\\(SR\\.UnexpectedParameterType, o\\.GetType\\(\\), typeof\\(FlowPosition\\)\\)","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowPosition.cs","lineNumber":69,"sourceCode":"        /// <summary>\n        /// Create a shallow copy of this objet\n        /// </summary>\n        /// <returns>A clone of this FlowPosition</returns>\n        public object Clone()\n        {\n            return new FlowPosition(_container, _flowNode, _offset);\n        }\n\n\n        // Compare two FixedTextPointer based on their flow order and offset\n        public int CompareTo(object o)\n        {\n            ArgumentNullException.ThrowIfNull(o);\n\n            FlowPosition flow = o as FlowPosition;\n            if (flow == null)\n            {\n                throw new ArgumentException(SR.Format(SR.UnexpectedParameterType, o.GetType(), typeof(FlowPosition)), nameof(o));\n            }\n\n            return _OverlapAwareCompare(flow);\n        }\n\n\n        /// <summary>\n        /// Compute hash code. A flow position is predominantly identified\n        /// by its flow node and the offset.\n        /// </summary>\n        /// <returns>int - hash code</returns>\n        public override int GetHashCode()\n        {\n            return _flowNode.GetHashCode()^_offset.GetHashCode();\n        }\n\n\n#if DEBUG","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowPosition.cs#L51-L87","documentation":"FlowPosition.CompareTo throws ArgumentException when the argument is not a FlowPosition. This method compares two flow positions to order them within the flow content; it is called during fixed-document node generation (GetFixedNodesForFlowRange).","triggerScenarios":"Comparing a FlowPosition to an object of another type, e.g. through Array.Sort, List<T>.BinarySearch, or direct calls passing mismatched objects.","commonSituations":"Custom pagination or fixed-flow-generation code that stores positions alongside other location objects (like TextPointer or ContentPosition) in one collection and sorts it.","solutions":["Guarantee all objects passed to CompareTo are FlowPosition instances","Separate heterogeneous position types into distinct typed collections","Use pattern matching to narrow before comparing"],"exampleFix":"// before\nlist.Sort(); // mixed element types\n// after\nlist.Sort((a, b) => ((FlowPosition)a).CompareTo((FlowPosition)b)); // after ensuring all elements are FlowPosition","handlingStrategy":"type-guard","validationCode":"if (position is FlowPosition fp) { result = thisPosition.CompareTo(fp); }","typeGuard":"static bool IsFlowPosition(object o) => o is FlowPosition;","tryCatchPattern":"try { a.CompareTo(b); } catch (ArgumentException) { /* b is not a FlowPosition */ }","preventionTips":["Keep FlowPosition instances in FlowPosition-typed collections","Never mix position types in one sorted collection","Narrow with pattern matching before comparing"],"tags":["wpf","icomparable","flowdocument"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}