{"record":{"id":"91d2a72e5e259928","repo":"dotnet/wpf","slug":"unsupported-selection","errorCode":null,"errorMessage":"Unsupported Selection","messagePattern":"Unsupported Selection","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/LocatorManager.cs","lineNumber":348,"sourceCode":"        /// an empty list</returns>\n        /// <exception cref=\"ArgumentNullException\">if selection is null</exception>\n        /// <exception cref=\"ArgumentException\">if no processor is registered for\n        /// selection's Type</exception>\n        public IList<ContentLocatorBase> GenerateLocators(Object selection)\n        {\n            VerifyAccess();\n            ArgumentNullException.ThrowIfNull(selection);\n\n            ICollection nodes = null;\n            SelectionProcessor selProcessor = GetSelectionProcessor(selection.GetType());\n\n            if (selProcessor != null)\n            {\n                nodes = (ICollection)selProcessor.GetSelectedNodes(selection);\n            }\n            else\n            {\n                throw new ArgumentException(\"Unsupported Selection\", nameof(selection));\n            }\n\n            IList<ContentLocatorBase> returnLocators = null;\n            PathNode pathRoot = PathNode.BuildPathForElements(nodes);\n\n            if (pathRoot != null)\n            {\n                SubTreeProcessor processor = GetSubTreeProcessor(pathRoot.Node);\n                Debug.Assert(processor != null, \"SubtreeProcessor can not be null\");\n\n                returnLocators = GenerateLocators(processor, pathRoot, selection);\n            }\n\n            // We never return null.  A misbehaved processor might return null so we fix it up.\n            if (returnLocators == null)\n                returnLocators = new List<ContentLocatorBase>(0);\n\n            return returnLocators;","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/LocatorManager.cs#L330-L366","documentation":"LocatorManager.GenerateLocators builds content locators for an annotation selection. It first resolves an ISelectionProcessor that can handle the selection's type; if no processor is registered for that selection type, it cannot produce locators and throws this ArgumentException.","triggerScenarios":"Calling LocatorManager.GenerateLocators(selection) with a selection object whose runtime type has no matching ISelectionProcessor registered (e.g. a custom or non-standard selection type, or a TextRange/TextSelection passed where the framework's TextSelectionHelper path is unavailable).","commonSituations":"Passing an arbitrary object instead of a supported selection (e.g. a string, DataObject or a UIElement instead of a TextSelection-like object); running in an environment where the text selection processor pipeline failed to initialize; custom annotation hosts that subclass selections without registering a processor.","solutions":["Inspect the selection object's runtime type and ensure it is a type supported by the annotations framework (e.g. an ITextSelection/TextSelection).","Verify the selection actually contains data; create it from a real selection source (e.g. a FlowDocumentReader/TextBox selection) rather than constructing it manually.","Register a custom ISelectionProcessor for the selection type if you use a custom selection class, before calling GenerateLocators.","Catch ArgumentException around GenerateLocators and degrade gracefully (skip locator generation)."],"exampleFix":"// before\nvar locators = locatorManager.GenerateLocators(myCustomSelectionObject);\n// after\nif (AnnotationSelectionHelper.IsSupportedSelection(myCustomSelectionObject))\n{\n    var locators = locatorManager.GenerateLocators(myCustomSelectionObject);\n}\nelse\n{\n    locators = null; // fall back: cannot anchor this selection\n}","handlingStrategy":"type-guard","validationCode":"var supported = selection != null && LocatorManager.FindSelectionProcessor(selection.GetType()) != null;\nif (!supported) throw new InvalidOperationException(\"No selection processor for \" + selection.GetType());","typeGuard":"static bool IsSupportedSelection(object selection, LocatorManager mgr) => selection != null && mgr.GetSelectionProcessor(selection.GetType()) != null;","tryCatchPattern":"try { locators = locatorManager.GenerateLocators(selection); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Unsupported Selection\")) { locators = null; }","preventionTips":["Create selections only from supported WPF sources (TextSelection from TextBox/RichTextBox/FlowDocument).","Register an ISelectionProcessor for any custom selection type before anchoring.","Unit-test GenerateLocators with every selection type your app can produce."],"tags":["wpf","annotations","argumentexception","selection"],"backgroundTag":"unsupported-operation","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"}