{"record":{"id":"9dfeccb00395283e","repo":"dotnet/wpf","slug":"sr-incorrectlocatorparttype-locatorpart-parttype-namespace","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/DataIdProcessor.cs","lineNumber":181,"sourceCode":"        /// </summary>\n        /// <param name=\"locatorPart\">locator part to be matched, must be of the type\n        /// handled by this processor</param>\n        /// <param name=\"startNode\">logical tree node to start search at</param>\n        /// <param name=\"continueResolving\">return flag indicating whether the search\n        /// should continue (presumably because the search was not exhaustive)</param>\n        /// <returns>returns a node that matches the locator part; null if no such\n        /// node is found</returns>\n        /// <exception cref=\"ArgumentNullException\">locatorPart or startNode are\n        /// null</exception>\n        /// <exception cref=\"ArgumentException\">locatorPart is of the incorrect\n        /// type</exception>\n        public override DependencyObject ResolveLocatorPart(ContentLocatorPart locatorPart, DependencyObject startNode, out bool continueResolving)\n        {\n            ArgumentNullException.ThrowIfNull(locatorPart);\n            ArgumentNullException.ThrowIfNull(startNode);\n\n            if (DataIdElementName != locatorPart.PartType)\n                throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $\"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}\"), nameof(locatorPart));\n\n            // Initial value\n            continueResolving = true;\n\n            // Get the values from the locator part...\n            string id = locatorPart.NameValuePairs[ValueAttributeName];\n            if (id == null)\n            {\n                throw new ArgumentException(SR.Format(SR.IncorrectLocatorPartType, $\"{locatorPart.PartType.Namespace}:{locatorPart.PartType.Name}\"), nameof(locatorPart));\n            }\n\n            // and from the node to examine.\n            string nodeId = GetNodeId(startNode);\n\n            if (nodeId != null)\n            {\n                if (nodeId.Equals(id))\n                {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/DataIdProcessor.cs#L163-L199","documentation":"DataIdProcessor.ResolveLocatorPart only accepts locator parts whose PartType equals the processor's DataIdElementName. If the supplied ContentLocatorPart has any other PartType, it throws ArgumentException with SR.IncorrectLocatorPartType describing the offending type's namespace:name, naming the 'locatorPart' parameter. Each anchor processor handles exactly one locator-part type, so mismatched parts must be routed elsewhere.","triggerScenarios":"Passing a ContentLocatorPart whose PartType is not DataIdProcessor's expected DataIdElementName into ResolveLocatorPart — e.g. feeding a PathProcessor/CharacterRangePart-type locator part to the DataId processor, or constructing a ContentLocatorPart with the wrong XName/type.","commonSituations":"Building annotation locators programmatically and mismatching processor types; deserializing annotation XML from another schema/version whose locator part type differs; iterating an anchor's locator parts in order and handing each to the wrong processor.","solutions":["Ensure the ContentLocatorPart is constructed with the exact PartType expected by DataIdProcessor (DataIdElementName) before calling ResolveLocatorPart.","Look up the correct processor via AnnotationResource/locator part type matching instead of calling a fixed processor directly.","If migrating old annotations, regenerate the locator part with the current DataId element type.","Check locatorPart.PartType against the expected type first and skip/route to the appropriate processor when different."],"exampleFix":"// before\nprocessor.ResolveLocatorPart(wrongLocatorPart, node, out continueResolving);\n// after\nif (DataIdProcessor.DataIdElementName == wrongLocatorPart.PartType)\n    processor.ResolveLocatorPart(wrongLocatorPart, node, out continueResolving);\nelse\n    matchingProcessor.ResolveLocatorPart(wrongLocatorPart, node, out continueResolving);","handlingStrategy":"type-guard","validationCode":"if (locatorPart == null || !DataIdProcessor.DataIdElementName.Equals(locatorPart.PartType))\n    throw new InvalidOperationException(\"Locator part is not a DataId part; route to correct processor.\");","typeGuard":"static bool IsDataIdPart(ContentLocatorPart part) =>\n    part != null && part.PartType == DataIdProcessor.DataIdElementName;","tryCatchPattern":"try { processor.ResolveLocatorPart(locatorPart, node, out var cont); }\ncatch (ArgumentException ex) when (ex.ParamName == \"locatorPart\") { RouteToMatchingProcessor(locatorPart, node); }","preventionTips":["Dispatch locator parts to processors by PartType match, not by fixed processor choice.","When constructing ContentLocatorPart, source the PartType from the processor's expected element name.","Validate locator parts during annotation deserialization/upgrade.","Add an assertion that locator.PartType matches before adding to an anchor's ContentLocator."],"tags":["wpf","annotations","argument-validation","type-mismatch"],"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-21T21:30:21.729Z"}