{"record":{"id":"4c6a8a7256903c87","repo":"dotnet/wpf","slug":"e-accessdenied","errorCode":"E_ACCESSDENIED","errorMessage":"UnauthorizedAccessException","messagePattern":"UnauthorizedAccessException","errorType":"exception","errorClass":"UnauthorizedAccessException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs","lineNumber":1360,"sourceCode":"                        // just return on E_NOTIMPL errors\n                        return false;\n\n                    case NativeMethods.E_OUTOFMEMORY:\n                        // Some OLEACC proxies produce out-of-memory for non-critical reasons:\n                        // notably, the treeview proxy will raise this if the target HWND no longer exists,\n                        // GetWindowThreadProcessID fails and it therefore won't be able to allocate shared\n                        // memory in the target process, so it incorrectly assumes OOM.\n                        throw new ElementNotAvailableException(e);\n                        \n                    case NativeMethods.E_INVALIDARG:\n                        // One or more arguments were invalid. This error occurs when the caller attempts to identify\n                        // a child object using an identifier that the server does not recognize. This error also results\n                        // when a client attempts to identify a child object within an object that has no children.\n                        throw new ArgumentException(SR.InvalidParameter);\n\n                    case NativeMethods.E_ACCESSDENIED:\n                        // This is returned when you call get_accValue to get the value of a password control.\n                        throw new UnauthorizedAccessException();\n\n                    case NativeMethods.E_UNEXPECTED:\n                        // An IAccessible server has been released unexpectedly but still has pending events.\n                        // If the current execution context is inside one of these event handlers it must be \n                        // abandoned.\n                        throw new ElementNotAvailableException(e);\n\n                    default:\n                        // we want to know when we get an exception we haven't seen before\n                        Debug.Fail(string.Format(CultureInfo.CurrentCulture, \"MsaaNativeProvider: IAccessible threw a COMException: {0}\", e.Message));\n                        break;\n                }\n            }\n            else if (e is InvalidCastException)\n            {\n                // sometimes Trident throws InvalidCastExceptions on elements from obsolete pages\n                throw new ElementNotAvailableException(e);\n            }","sourceCodeStart":1342,"sourceCodeEnd":1378,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/Accessible.cs#L1342-L1378","documentation":"The IAccessible server returned E_ACCESSDENIED and the provider maps it to UnauthorizedAccessException. The documented trigger in this code is calling get_accValue on a password control: MSAA deliberately refuses to hand back the masked value. This is an intentional security denial by the server, not a transient failure.","triggerScenarios":"Reading the ValuePattern/value property of an Edit control with ES_PASSWORD style through the MSAA client-side provider; any other IAccessible property call the server refuses with E_ACCESSDENIED.","commonSituations":"Automation or test tooling trying to read a login/password textbox's value; screen-scraping tools hitting masked fields; UI tests asserting on credential fields.","solutions":["Do not read password field values via UIA/MSAA — restructure the test to verify the field has focus/type instead of its content.","Check AccessibilityObject properties on your own controls; clear ES_PASSWORD only in controlled test builds if you truly need the value.","Catch UnauthorizedAccessException around Value retrieval and treat it as 'field is protected'.","Use the app's own instrumentation (test hooks, logs) to obtain the value rather than scraping protected UI."],"exampleFix":"// before\nvar pwd = pwdBox.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;\nvar value = pwd.Current.Value; // UnauthorizedAccessException for password fields\n// after\nvar isPassword = (bool)pwdBox.GetCurrentPropertyValue(AutomationElement.IsPasswordProperty, true);\nif (isPassword)\n{\n    // verify behavior (focus, type, keystrokes) instead of reading the value\n}\nelse\n{\n    var value = ((ValuePattern)pwdBox.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;\n}","handlingStrategy":"try-catch","validationCode":"// Skip protected fields before reading values:\nbool IsPasswordField(AutomationElement el) =>\n    (bool)el.GetCurrentPropertyValue(AutomationElement.IsPasswordProperty, true);","typeGuard":null,"tryCatchPattern":"try\n{\n    var v = ((ValuePattern)el.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;\n}\ncatch (UnauthorizedAccessException)\n{\n    // password/protected field: do not attempt further reads\n}","preventionTips":["Check AutomationElement.IsPasswordProperty before reading Value.","Never assert on credential field contents in automated tests; assert on behavior instead.","Avoid scraping masked UI fields — use app-level test hooks for sensitive data.","Treat UnauthorizedAccessException from MSAA reads as a permanent, not retryable, denial."],"tags":["uiautomation","wpf","msaa","access-denied","password-field"],"backgroundTag":"permission-denied","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"}