dotnet/wpf · error · InvalidOperationException

Invalid type specified for AutomationIdentifier

Error message

Invalid type specified for AutomationIdentifier

What it means

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.

Solutions

  1. Ensure the UIAutomation native components and managed assemblies are from matching .NET/WPF versions
  2. Check whether a custom property/pattern id collides with a reserved native id
  3. Repro under a debugger to inspect the returned AutomationIdType before the throw
  4. Report as a WPF bug if reproducible with stock registration APIs
Defensive patterns

Strategy: try-catch

Try / catch

try { var id = AutomationIdentifier.Register(...); }
catch (InvalidOperationException ex) { log.Fatal("UIA identifier type invariant violated", ex); throw; }

Prevention

When it happens

Trigger: Registering an automation identifier whose native type lookup returns an unexpected AutomationIdType enum value — outside Event, TextAttribute, Pattern, or ControlType.

Common situations: Version mismatch between managed UIAutomationTypes and the native UIAutomationCore DLL; custom property/attribute registration hitting an unhandled native type.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/67014cc47baf202a. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationTypes/System/Windows/Automation/AutomationIdentifier.cs:169

            {
                // See if instance already exists...
                AutomationIdentifier autoid = (AutomationIdentifier)_idTable[id];
                if (autoid != null)
                {
                    return autoid;
                }

                // If not, create one...
                switch (type)
                {
                    case UiaCoreTypesApi.AutomationIdType.Property:      autoid = new AutomationProperty(id, programmaticName);      break;
                    case UiaCoreTypesApi.AutomationIdType.Event:         autoid = new AutomationEvent(id, programmaticName);         break;
                    case UiaCoreTypesApi.AutomationIdType.TextAttribute: autoid = new AutomationTextAttribute(id, programmaticName); break;
                    case UiaCoreTypesApi.AutomationIdType.Pattern:       autoid = new AutomationPattern(id, programmaticName);       break;
                    case UiaCoreTypesApi.AutomationIdType.ControlType:   autoid = new ControlType(id, programmaticName);             break;

                    default: Debug.Fail("Invalid type specified for AutomationIdentifier");
                        throw new InvalidOperationException("Invalid type specified for AutomationIdentifier");
                }

                _idTable[id] = autoid;
                return autoid;
            }
        }

        internal static AutomationIdentifier LookupById(UiaCoreTypesApi.AutomationIdType type, int id)
        {
            AutomationIdentifier autoid;
            lock (_idTable)
            {
                autoid = (AutomationIdentifier) _idTable[id];
            }

            if(autoid == null)
            {
                return null;

View on GitHub (pinned to 81131a70a4)