{"record":{"id":"67014cc47baf202a","repo":"dotnet/wpf","slug":"invalid-type-specified-for-automationidentifier","errorCode":null,"errorMessage":"Invalid type specified for AutomationIdentifier","messagePattern":"Invalid type specified for AutomationIdentifier","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/AutomationIdentifier.cs","lineNumber":169,"sourceCode":"            {\n                // See if instance already exists...\n                AutomationIdentifier autoid = (AutomationIdentifier)_idTable[id];\n                if (autoid != null)\n                {\n                    return autoid;\n                }\n\n                // If not, create one...\n                switch (type)\n                {\n                    case UiaCoreTypesApi.AutomationIdType.Property:      autoid = new AutomationProperty(id, programmaticName);      break;\n                    case UiaCoreTypesApi.AutomationIdType.Event:         autoid = new AutomationEvent(id, programmaticName);         break;\n                    case UiaCoreTypesApi.AutomationIdType.TextAttribute: autoid = new AutomationTextAttribute(id, programmaticName); break;\n                    case UiaCoreTypesApi.AutomationIdType.Pattern:       autoid = new AutomationPattern(id, programmaticName);       break;\n                    case UiaCoreTypesApi.AutomationIdType.ControlType:   autoid = new ControlType(id, programmaticName);             break;\n\n                    default: Debug.Fail(\"Invalid type specified for AutomationIdentifier\");\n                        throw new InvalidOperationException(\"Invalid type specified for AutomationIdentifier\");\n                }\n\n                _idTable[id] = autoid;\n                return autoid;\n            }\n        }\n\n        internal static AutomationIdentifier LookupById(UiaCoreTypesApi.AutomationIdType type, int id)\n        {\n            AutomationIdentifier autoid;\n            lock (_idTable)\n            {\n                autoid = (AutomationIdentifier) _idTable[id];\n            }\n\n            if(autoid == null)\n            {\n                return null;","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/AutomationIdentifier.cs#L151-L187","documentation":"AutomationIdentifier.Register throws InvalidOperationException(\"Invalid type specified for AutomationIdentifier\") when the native UIA type id (UiaCoreTypesApi.AutomationIdType) returned from the underlying lookup is not one of Event, TextAttribute, Pattern, or ControlType. This is an internal invariant violation — the id table cannot classify the identifier. It is also guarded by Debug.Fail, so it typically indicates a corrupted or mismatched native interop result.","triggerScenarios":"Registering an automation identifier whose native type lookup returns an unexpected AutomationIdType enum value — outside Event, TextAttribute, Pattern, or ControlType.","commonSituations":"Version mismatch between managed UIAutomationTypes and the native UIAutomationCore DLL; custom property/attribute registration hitting an unhandled native type.","solutions":["Ensure the UIAutomation native components and managed assemblies are from matching .NET/WPF versions","Check whether a custom property/pattern id collides with a reserved native id","Repro under a debugger to inspect the returned AutomationIdType before the throw","Report as a WPF bug if reproducible with stock registration APIs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var id = AutomationIdentifier.Register(...); }\ncatch (InvalidOperationException ex) { log.Fatal(\"UIA identifier type invariant violated\", ex); throw; }","preventionTips":["Keep WPF managed assemblies and native UIAutomation components version-aligned","Do not hand-craft or collide automation ids; use the registration APIs","Capture dumps when this fires — it signals an internal invariant break, not caller error"],"tags":["uiautomation","internal-invariant","interop"],"backgroundTag":"internal-invariant-violation","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"}