{"record":{"id":"ea41658df48c692c","repo":"dotnet/wpf","slug":"notsupportedexception-interopautomationprovider","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"info","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/InteropAutomationProvider.cs","lineNumber":88,"sourceCode":"            return null;\n        }\n\n        ///\n        Rect IRawElementProviderFragment.BoundingRectangle\n        {\n            get { return Rect.Empty; }\n        }\n\n        ///\n        IRawElementProviderSimple [] IRawElementProviderFragment.GetEmbeddedFragmentRoots()\n        {\n            return null;\n        }\n\n        ///        \n        void IRawElementProviderFragment.SetFocus()\n        {\n            throw new NotSupportedException();\n        }\n\n        ///\n        IRawElementProviderFragmentRoot IRawElementProviderFragment.FragmentRoot\n        {\n            get { return null; }\n        }\n        \n        #endregion IRawElementProviderFragment\n\n        #region IRawElementProviderFragmentRoot\n\n        ///\n        IRawElementProviderFragment IRawElementProviderFragmentRoot.ElementProviderFromPoint( double x, double y )\n        {\n            return null;\n        }\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Automation/InteropAutomationProvider.cs#L70-L106","documentation":"InteropAutomationProvider is a bridge provider representing an already-dispatched/external element; as an IRawElementProviderFragment it does not support being focused. Its explicit SetFocus implementation throws NotSupportedException to signal clients that focus cannot be set through this provider.","triggerScenarios":"A UIA client (or wrapper code) calls SetFocus on the IRawElementProviderFragment interface of an InteropAutomationProvider — e.g. InvokePattern or focus logic that resolves the provider to the bridge fragment and attempts programmatic focus.","commonSituations":"UIA clients automating hosted/HWND-bridged content and trying to focus the bridge provider instead of the real element; test frameworks calling SetFocus generically on any provider returned from a fragment walk.","solutions":["Focus the real underlying element instead of the bridge provider (obtain the actual UIElement/AutomationPeer and call Focus()).","Have the client check pattern/interface support before calling SetFocus on the fragment node.","Route focus through the element's own automation peer (Peer.SetFocus) rather than the interop provider.","Treat NotSupportedException as 'not focusable via this node' and fall back to keyboard emulation (SendInput)."],"exampleFix":"// before\n((IRawElementProviderFragment)interopProvider).SetFocus();\n// after\nvar peer = UIElementAutomationPeer.CreatePeerForElement(targetElement);\nif (peer != null && peer.IsFocusable())\n{\n    peer.SetFocus();\n}","handlingStrategy":"type-guard","validationCode":"if (provider is not ElementProxy) { /* focus the real element instead */ }","typeGuard":"bool CanSetFocusViaPeer(AutomationPeer peer) => peer != null && peer.IsFocusable();","tryCatchPattern":"try\n{\n    providerFragment.SetFocus();\n}\ncatch (NotSupportedException)\n{\n    // bridge provider is not focusable; focus the underlying element instead\n    targetElement.Focus();\n}","preventionTips":["Focus the real UIElement or its AutomationPeer, not interop bridge providers","Check pattern support (IPattern.IsSupported) before focus operations","Don't walk IRawElementProviderFragment roots expecting focus support on every node","Use keyboard emulation fallback for non-focusable bridge nodes"],"tags":["wpf","ui-automation","not-supported","interop","focus"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}