{"record":{"id":"b3b5329be2e24717","repo":"dotnet/wpf","slug":"sr-unsupportedpattern-automationelement","errorCode":null,"errorMessage":"SR.UnsupportedPattern","messagePattern":"SR\\.UnsupportedPattern","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/AutomationElement.cs","lineNumber":550,"sourceCode":"        /// <summary>\n        /// Get a pattern class from this object\n        /// </summary>\n        /// <param name=\"pattern\">AutomationPattern indicating the pattern to return</param>\n        /// <returns>Returns the pattern as an object, if currently supported</returns>\n        /// <remarks>\n        /// Throws InvalidOperationException if the pattern is not supported.\n        /// \n        /// This API gets the pattern based on availability at this point in time,\n        /// without checking the cache. For some types of UI, this API will incur\n        /// a cross-process performance hit. To access patterns in this AutomationElement's\n        /// cache, use GetCachedPattern instead.\n        /// </remarks>\n        public object GetCurrentPattern(AutomationPattern pattern)\n        {\n            object retObject;\n            if (!TryGetCurrentPattern(pattern, out retObject))\n            {\n                throw new InvalidOperationException(SR.UnsupportedPattern);\n            }\n\n            return retObject;\n        }\n\n\n        /// <summary>\n        /// Get a pattern class from this object\n        /// </summary>\n        /// <param name=\"pattern\">an object repressenting the AutomationPattern indicating\n        /// the pattern to return</param>\n        /// <param name=\"patternObject\">the returned pattern object will be an object \n        /// implementing the control pattern interface if the pattern is supported else \n        /// the object will be null.</param>\n        /// <returns>Returns true, if currently supported</returns>\n        /// <remarks>\n        /// This API gets the pattern based on availability at this point in time,\n        /// without checking the cache. For some types of UI, this API will incur","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/AutomationElement.cs#L532-L568","documentation":"AutomationElement.GetCurrentPattern resolves a pattern object for the element via TryGetCurrentPattern; when the element does not support the requested pattern, the throwing wrapper raises InvalidOperationException with SR.UnsupportedPattern. It means the requested AutomationPattern is not currently supported by the element (or the provider did not expose it).","triggerScenarios":"Calling element.GetCurrentPattern(somePattern) where TryGetCurrentPattern returns false, e.g. requesting InvokePattern on a read-only text element, or requesting a pattern from a provider that only implements it conditionally.","commonSituations":"Assuming all controls support a pattern (buttons vs. text blocks); patterns disappearing dynamically when a control is disabled or changes state; mapping UI element types to patterns incorrectly in test frameworks.","solutions":["Use TryGetCurrentPattern and branch on its return value instead of GetCurrentPattern","Check element support arrays (element.GetSupportedPatterns() or GetCurrentPropertyValue(AutomationElement.IsInvokePatternAvailableProperty)) before requesting","Adjust the element lookup condition to target the right control type for the desired pattern"],"exampleFix":"// before\nvar invoke = (InvokePattern)element.GetCurrentPattern(InvokePattern.Pattern);\n// after\nif (element.TryGetCurrentPattern(InvokePattern.Pattern, out var p))\n{\n    var invoke = (InvokePattern)p;\n}\nelse\n{\n    // element does not support Invoke; pick an alternative pattern\n}","handlingStrategy":"validation","validationCode":"bool supported = (bool)element.GetCurrentPropertyValue(AutomationElement.IsInvokePatternAvailableProperty);\nif (supported) { /* safe to GetCurrentPattern(InvokePattern.Pattern) */ }","typeGuard":null,"tryCatchPattern":"try { var p = element.GetCurrentPattern(pat); }\ncatch (InvalidOperationException) { UseAlternativeInteraction(element); }","preventionTips":["Use TryGetCurrentPattern instead of GetCurrentPattern by default","Check Is*PatternAvailable properties before requesting","Map control types to expected patterns in automation helpers"],"tags":["uiautomation","wpf","unsupported-pattern"],"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"}