{"record":{"id":"7cfc73cba6513c5b","repo":"dotnet/wpf","slug":"sr-format-sr-invalidlocatorpart-segmentattribute","errorCode":null,"errorMessage":"SR.Format(SR.InvalidLocatorPart, SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo))","messagePattern":"SR\\.Format\\(SR\\.InvalidLocatorPart, SegmentAttribute \\+ segmentNumber\\.ToString\\(NumberFormatInfo\\.InvariantInfo\\)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/TextSelectionProcessor.cs","lineNumber":441,"sourceCode":"\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\">the number of the segment to extract values for</param>\n        /// <param name=\"startOffset\">value of offset attribute</param>\n        /// <param name=\"endOffset\">value of length attribute</param>\n        private static void GetLocatorPartSegmentValues(ContentLocatorPart locatorPart, int segmentNumber, out int startOffset, out int endOffset)\n        {\n            if (segmentNumber < 0)\n                throw new ArgumentException(nameof(segmentNumber));\n\n            ReadOnlySpan<char> segmentString = locatorPart.NameValuePairs[SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)].AsSpan();\n\n            Span<Range> splitRegions = stackalloc Range[3];\n            if (segmentString.Split(splitRegions, Separator) != 2)\n            {\n                throw new ArgumentException(SR.Format(SR.InvalidLocatorPart, SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)));\n            }\n\n            startOffset = int.Parse(segmentString[splitRegions[0]], NumberFormatInfo.InvariantInfo);\n            endOffset = int.Parse(segmentString[splitRegions[1]], NumberFormatInfo.InvariantInfo);\n        }\n\n        /// <summary>\n        ///     Returns the TextContainer for a node that contains text.  If the node\n        ///     doesn't have a TextContainer this method returns null.\n        /// </summary>\n        private ITextContainer GetTextContainer(DependencyObject startNode)\n        {\n            Debug.Assert(startNode != null);\n\n            ITextContainer textContainer = null;\n            IServiceProvider serviceProvider = startNode as IServiceProvider;\n            if (serviceProvider != null)\n            {","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/TextSelectionProcessor.cs#L423-L459","documentation":"GetLocatorPartSegmentValues throws ArgumentException(SR.InvalidLocatorPart, SegmentAttribute+n) when the segment attribute 'Segment<n>' is missing or its value does not split into exactly two parts (start,end) around the separator. The segment string format is invalid or the attribute is absent.","triggerScenarios":"Locator part lacks the 'Segment0' (etc.) attribute, or its value contains the wrong number of separators (not exactly one), so segmentString.Split(...) != 2.","commonSituations":"Hand-edited persisted annotation XML; attributes keyed with wrong culture/invariant formatting; locator parts constructed manually without the 'start,end' format; version drift in serialized locator format.","solutions":["Ensure every segment index 0..Count-1 has a 'Segment<n>' attribute formatted 'start,end' (two parts, invariant numbers)","Create locator parts via TextSelectionProcessor.CreateLocatorPart rather than manual construction","Validate/repair persisted annotation payloads before re-resolving"],"exampleFix":"// before\npart.NameValuePairs[\"Segment0\"] = \"10;25\"; // wrong separator\n// after\npart.NameValuePairs[\"Segment0\"] = \"10,25\";","handlingStrategy":"validation","validationCode":"string seg = part.NameValuePairs[\"Segment\" + n];\nbool valid = seg != null && seg.Split(',').Length == 2;\nif (!valid) throw new InvalidOperationException($\"Segment{n} must be 'start,end'.\");","typeGuard":null,"tryCatchPattern":"try { GetLocatorPartSegmentValues(part, n, out s, out e); }\ncatch (ArgumentException) { /* regenerate the locator part from the current selection */ }","preventionTips":["Format segment values as invariant 'start,end' with exactly one comma","Regenerate locator parts instead of editing serialized XML by hand","Round-trip test persisted annotations after upgrades"],"tags":["wpf","annotations","invalid-argument-format","locator-part"],"backgroundTag":"invalid-argument-format","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"}