{"record":{"id":"647c309215290588","repo":"dotnet/wpf","slug":"sr-incorrectlocatorparttype-locatorpart-parttype-namespace-647c30","errorCode":null,"errorMessage":"SR.IncorrectLocatorPartType ({locatorPart.PartType.Namespace}:{locatorPart.PartType.Name})","messagePattern":"SR\\.IncorrectLocatorPartType \\((.+?):(.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs","lineNumber":493,"sourceCode":"                throw new ArgumentException(SR.WrongSelectionType, $\"selection: type={selection.GetType()}\");\n            }\n\n            return anchor;\n        }\n\n        /// <summary>\n        ///     Extracts the values of attributes from a locator part.\n        /// </summary>\n        /// <param name=\"locatorPart\">the locator part to extract values from</param>\n        /// <param name=\"segmentNumber\">number of segment value to retrieve</param>\n        /// <param name=\"start\">the start point value based on StartXAttribute and StartYAttribute values</param>\n        /// <param name=\"end\">the end point value based on EndXAttribyte and EndYattribute values</param>\n        private void GetLocatorPartSegmentValues(ContentLocatorPart locatorPart, int segmentNumber, out Point start, out Point end)\n        {\n            ArgumentNullException.ThrowIfNull(locatorPart);\n\n            if (FixedTextElementName != locatorPart.PartType)\n                throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $\"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}\"), nameof(locatorPart));\n\n            string segmentValue = locatorPart.NameValuePairs[TextSelectionProcessor.SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)];\n            if (segmentValue == null)\n                throw new ArgumentException(SR.Format(SR.InvalidLocatorPart, TextSelectionProcessor.SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)));\n\n            ReadOnlySpan<char> segmentValueSpan = segmentValue.AsSpan();\n            Span<Range> splitRegions = stackalloc Range[5];\n\n            if (segmentValueSpan.Split(splitRegions, TextSelectionProcessor.Separator) != 4)\n                throw new ArgumentException(SR.Format(SR.InvalidLocatorPart, TextSelectionProcessor.SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)));\n\n            start = GetPoint(segmentValueSpan[splitRegions[0]], segmentValueSpan[splitRegions[1]]);\n            end = GetPoint(segmentValueSpan[splitRegions[2]], segmentValueSpan[splitRegions[3]]);\n        }\n\n        /// <summary>\n        /// Calculates <see cref=\"Point\"/> out of X and Y values supplied as a <see cref=\"string\"/>.\n        /// </summary>","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs#L475-L511","documentation":"GetLocatorPartSegmentValues parses segment geometry out of a ContentLocatorPart. It first requires locatorPart.PartType to equal FixedTextElementName; any other part type throws ArgumentException(SR.IncorrectLocatorPartType) including the fully-qualified part type name. This protects against feeding e.g. a tree-selection locator part into the fixed processor.","triggerScenarios":"Calling ResolveLocatorPart (which calls GetLocatorPartSegmentValues) with a ContentLocatorPart whose PartType differs from the FixedText element name — e.g. a ContentLocatorPart created for the tree selection processor.","commonSituations":"Cross-wiring processors: annotations created under a TreeSelectionProcessor resolved through the fixed processor; manually built locator parts with wrong PartType; loading annotation stores written by other applications.","solutions":["Create locator parts with FixedTextSelectionProcessor.CreateLocatorPart / matching PartType.","Check locatorPart.PartType == FixedTextSelectionProcessor.FixedTextElementName before resolving.","Route each locator through the processor whose Id/PartType matches."],"exampleFix":"// before\nvar part = new ContentLocatorPart(treeSelectionProcessorPartType);\nfixedProcessor.ResolveLocatorPart(part, docPage, out level);\n// after\nvar part = new ContentLocatorPart(FixedTextSelectionProcessor.FixedTextElementName);\npart.NameValuePairs[\"Count\"] = \"1\";\nfixedProcessor.ResolveLocatorPart(part, docPage, out level);","handlingStrategy":"validation","validationCode":"if (locatorPart.PartType != FixedTextSelectionProcessor.FixedTextElementName) throw new InvalidOperationException($\"Unexpected PartType {locatorPart.PartType.Name}\");","typeGuard":null,"tryCatchPattern":"try { processor.ResolveLocatorPart(part, node, out var level); } catch (ArgumentException ex) { /* wrong processor for this part type */ }","preventionTips":["Route each ContentLocatorPart to the processor that created it","Check PartType before resolution","Avoid cross-loading annotation stores from foreign apps"],"tags":["wpf","annotations","locator-part"],"backgroundTag":"invalid-argument-value","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"}