{"record":{"id":"990dc1dc6ae03a8c","repo":"dotnet/wpf","slug":"sr-invalidlocatorpart-segmentattribute-n","errorCode":null,"errorMessage":"SR.InvalidLocatorPart (SegmentAttribute{n})","messagePattern":"SR\\.InvalidLocatorPart \\(SegmentAttribute(.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs","lineNumber":497,"sourceCode":"        }\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>\n        /// <param name=\"xValue\">x string value</param>\n        /// <param name=\"yValue\">y string value</param>\n        /// <returns>Initialized <see cref=\"Point\"/> structure.</returns>\n        private static Point GetPoint(ReadOnlySpan<char> xValue, ReadOnlySpan<char> yValue)","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs#L479-L515","documentation":"After confirming the part type, GetLocatorPartSegmentValues reads NameValuePairs['Segment{n}'] for the requested segment number. A missing (null) value means the locator part is malformed, so it throws ArgumentException(SR.InvalidLocatorPart, Segment{n}).","triggerScenarios":"ResolveLocatorPart invoked with a FixedText locator part lacking the 'Segment0'/'Segment1'... attribute for a given segment index, e.g. Count says 2 segments but only Segment0 exists.","commonSituations":"Corrupt or hand-edited annotation XML; programmatic construction that sets Count higher than the number of Segment attributes stored; attribute naming typos (lowercase 'segment').","solutions":["Ensure NameValuePairs contains Segment{i} for every i in [0, Count).","Let GenerateLocatorParts create segments instead of manual construction.","When editing stored annotations, preserve every Segment attribute."],"exampleFix":"// before\npart.NameValuePairs[\"Count\"] = \"2\";\npart.NameValuePairs[\"Segment0\"] = \"...\"; // Segment1 missing\n// after\npart.NameValuePairs[\"Count\"] = \"2\";\npart.NameValuePairs[\"Segment0\"] = \"...\";\npart.NameValuePairs[\"Segment1\"] = \"...\";","handlingStrategy":"validation","validationCode":"int count = int.Parse(part.NameValuePairs[\"Count\"], CultureInfo.InvariantCulture);\nfor (int i = 0; i < count; i++) if (!part.NameValuePairs.ContainsKey(\"Segment\" + i)) throw new InvalidOperationException($\"Missing Segment{i}\");","typeGuard":null,"tryCatchPattern":"try { processor.ResolveLocatorPart(part, node, out var level); } catch (ArgumentException ex) { /* malformed locator part — skip or rebuild */ }","preventionTips":["Keep Count consistent with the number of Segment attributes","Validate annotation XML schema on load","Generate segments programmatically, never by hand"],"tags":["wpf","annotations","locator-part"],"backgroundTag":"missing-required-argument","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"}