dotnet/wpf · error · ArgumentException
SR.IncorrectLocatorPartType
Error message
SR.IncorrectLocatorPartType ({locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}) What it means
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.
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.
Example fix
// before var part = new ContentLocatorPart(treeSelectionProcessorPartType); fixedProcessor.ResolveLocatorPart(part, docPage, out level); // after var part = new ContentLocatorPart(FixedTextSelectionProcessor.FixedTextElementName); part.NameValuePairs["Count"] = "1"; fixedProcessor.ResolveLocatorPart(part, docPage, out level);
Defensive patterns
Strategy: validation
Validate before calling
if (locatorPart.PartType != FixedTextSelectionProcessor.FixedTextElementName) throw new InvalidOperationException($"Unexpected PartType {locatorPart.PartType.Name}"); Try / catch
try { processor.ResolveLocatorPart(part, node, out var level); } catch (ArgumentException ex) { /* wrong processor for this part type */ } Prevention
- Route each ContentLocatorPart to the processor that created it
- Check PartType before resolution
- Avoid cross-loading annotation stores from foreign apps
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.Format(SR.InvalidLocatorPart, SegmentAttribute +…
- SR.InvalidLocatorPart (Count)
- SR.InvalidLocatorPart
- anchorLocator.Parts
- annotation component
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/647c309215290588.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/FixedTextSelectionProcessor.cs:493
throw new ArgumentException(SR.WrongSelectionType, $"selection: type={selection.GetType()}");
}
return anchor;
}
/// <summary>
/// Extracts the values of attributes from a locator part.
/// </summary>
/// <param name="locatorPart">the locator part to extract values from</param>
/// <param name="segmentNumber">number of segment value to retrieve</param>
/// <param name="start">the start point value based on StartXAttribute and StartYAttribute values</param>
/// <param name="end">the end point value based on EndXAttribyte and EndYattribute values</param>
private void GetLocatorPartSegmentValues(ContentLocatorPart locatorPart, int segmentNumber, out Point start, out Point end)
{
ArgumentNullException.ThrowIfNull(locatorPart);
if (FixedTextElementName != locatorPart.PartType)
throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}"), nameof(locatorPart));
string segmentValue = locatorPart.NameValuePairs[TextSelectionProcessor.SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)];
if (segmentValue == null)
throw new ArgumentException(SR.Format(SR.InvalidLocatorPart, TextSelectionProcessor.SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)));
ReadOnlySpan<char> segmentValueSpan = segmentValue.AsSpan();
Span<Range> splitRegions = stackalloc Range[5];
if (segmentValueSpan.Split(splitRegions, TextSelectionProcessor.Separator) != 4)
throw new ArgumentException(SR.Format(SR.InvalidLocatorPart, TextSelectionProcessor.SegmentAttribute + segmentNumber.ToString(NumberFormatInfo.InvariantInfo)));
start = GetPoint(segmentValueSpan[splitRegions[0]], segmentValueSpan[splitRegions[1]]);
end = GetPoint(segmentValueSpan[splitRegions[2]], segmentValueSpan[splitRegions[3]]);
}
/// <summary>
/// Calculates <see cref="Point"/> out of X and Y values supplied as a <see cref="string"/>.
/// </summary>View on GitHub (pinned to 81131a70a4)