Skip to content

Windows Automation tree breaking change #8679

Open

Description

@Tobiidave

Description

Dotnet 8 renders the controls in the Windows automation tree differently compared to earlier dotnet versions.
Buttons in an itemscontrol can't be found anymore, breaking the existing automation.

Using the "Accessabilitiy Insights for Windows" shows a different graph compared to dotnet 6/7 (see below)

Reproduction Steps

WpfApp3.zip

Expected behavior

With <TargetFramework>net7.0-windows</TargetFramework> , the automation tree looks like
pane "Desktop 1"
window "MainWindow"
title bar ''
button "TopButton"
button "ItemButton1"

Actual behavior

With <TargetFramework>net8.0-windows</TargetFramework>, the automation tree looks like

pane "Desktop 1"
window "MainWindow"
title bar ''
button "TopButton"
list view #note that here was the "ItemButton1" - now it is not present anymore!

Regression?

Yes

Known Workarounds

No response

Impact

The UI Tests for our applications breaks; need workarounds

Configuration

Microsoft.WindowsDesktop.App 8.0.1
Microsoft.NETCore.App 8.0.1
windows 10.19045.3803
x64

Vs2022

Other information

No response

Activity

  1. added
    Investigate
    on Jan 12, 2024
  2. lindexi commented on Jan 12, 2024

    @lindexi
    Member

    @Tobiidave Maybe this behavior be changed by #6862

    I'm not sure.

  3. Tobiidave commented on Jan 12, 2024

    @Tobiidave
    Author

    I don't know how the 6862 affected this. But the problem exists in both 8.0.0 and 8.0.1

  4. psmulovics commented on Jan 12, 2024

    @psmulovics

    I do not think you can expect automation trees to stay intact between major version upgrades - I would consider it business-as-usual these getting broken on major upgrade.

  5. Tobiidave commented on Jan 15, 2024

    @Tobiidave
    Author

    @psmulovics In this case the WPF controls change type and are not usable anymore, I edited and tried to emphasize this by a small comment. It is not only a tree re-ordering issue, but elements that were clickable can not be found anymore! Ofc, any suggested workarounds are welcome! We have paused dotnet8 migration due to this, the automation tech is central to our development.

  6. lindexi commented on Jan 19, 2024

    @lindexi
    Member

    We have paused dotnet8 migration due to this

    @Tobiidave Sorry hear that. I still haven't found the exact change code for this issues.

  7. jimm98y commented on Jan 20, 2024

    @jimm98y

    I've created a test app and I've tried to restore the original behavior simply by setting this in OnStartup:

    System.AppContext.SetSwitch("Switch.System.Windows.Controls.ItemsControlDoesNotSupportAutomation", true);

    Unfortunately, it looks like it's too late and the value is already set and cached. So I had to use reflection instead:

    var accessibilitySwitches = Type.GetType("System.Windows.AccessibilitySwitches, WindowsBase, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
    var field = accessibilitySwitches.GetField("_ItemsControlDoesNotSupportAutomation", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static | BindingFlags.DeclaredOnly);
    field.SetValue(null, 1);

    This seems to fix the issue and restore the original pre-NET8 behavior. To test it, I used the following piece of code in the test app from this bug report:

    public static void VerifyMainWindowAccessibility()
    {
        AutomationElement mainWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "MainWindow"));
        Debug.WriteLine(DumpUIATree(mainWindow));
    }
    
    private static string DumpUIATree(AutomationElement element)
    {
        var s = element.Current.Name + " : " + element.Current.ControlType.ProgrammaticName;
        DumpChildrenRecursively(element, 1, ref s);
        return s;
    }
    
    private static List<AutomationElement> GetChildNodes(AutomationElement automationElement)
    {
        var children = new List<AutomationElement>();
        TreeWalker walker = TreeWalker.ControlViewWalker;
        AutomationElement child = walker.GetFirstChild(automationElement);
        while (child != null)
        {
            children.Add(child);
            child = walker.GetNextSibling(child);
        }
        return children;
    }
    
    private static void DumpChildrenRecursively(AutomationElement node, int level, ref string s)
    {
        var children = GetChildNodes(node);
        foreach (AutomationElement child in children)
        {
            if (child != null)
            {
                for (int i = 0; i < level; i++)
                    s += "-";
                s += " " + child.Current.Name + " : " + child.Current.ControlType?.ProgrammaticName + "\r\n";
                DumpChildrenRecursively(child, level + 1, ref s);
            }
        }
    }

    NET8 before the fix:

    - TopButton : ControlType.Button
    -- TopButton : ControlType.Text
    -  : ControlType.List
    -- ItemButton1 : ControlType.DataItem
    --- ItemButton1 : ControlType.Text
    

    NET8 after the fix:

    - TopButton : ControlType.Button
    -- TopButton : ControlType.Text
    - ItemButton1 : ControlType.Button
    -- ItemButton1 : ControlType.Text
    

    NET6 behavior:

    - TopButton : ControlType.Button
    -- TopButton : ControlType.Text
    - ItemButton1 : ControlType.Button
    -- ItemButton1 : ControlType.Text
    
  8. self-assigned this
    on Jan 23, 2024
  9. Kuldeep-MS commented on Jan 23, 2024

    @Kuldeep-MS
    Contributor

    I am investigating the issue from my end.

  10. Tobiidave commented on Jan 23, 2024

    @Tobiidave
    Author

    Good work guys - but be sure to test this with the ms app "Accessibilities for Windows" to make sure it looks the same.
    It shows larger differences than what I see from your inspection using the TreeWalker-code above!

  11. walterlv commented on Jan 30, 2024

    @walterlv
    Contributor

    I've tested this code below to set the AppContext switch and find it worked.

    public class Program
    {
        [STAThread]
        static void Main()
        {
            AppContext.SetSwitch("Switch.System.Windows.Controls.ItemsControlDoesNotSupportAutomation", true);
    
            var app = new App();
            app.InitializeComponent();
            app.Run();
        }
    }

    This means that if it is late on startup, it can be set before the WPF initialization which reflection is not needed. @jimm98y

  12. Tobiidave commented on Aug 20, 2024

    @Tobiidave
    Author

    Hi. So now when .Net7 is out of support and this issue is blocking from moving to .Net8, what do think we should do with our app and +1000 customers?

  13. lindexi commented on Aug 21, 2024

    @lindexi
    Member

    @Tobiidave Sorry, I do not think the PR can enter .NET 9

  14. Tobiidave commented on Aug 21, 2024

    @Tobiidave
    Author

    So how would we handle these changes in the windows automation tree?

  15. Kuldeep-MS commented on Aug 21, 2024

    @Kuldeep-MS
    Contributor

    @Tobiidave - Could you please take a look at this comment, where the same scenario is explained in detail? Please let us know if it isn't working for you.

  16. Tobiidave commented on Aug 23, 2024

    @Tobiidave
    Author

    Hi - I took the test project attached to this thread, added

        public App()
        {
            AppContext.SetSwitch("Switch.System.Windows.Controls.ItemsControlDoesNotSupportAutomation", true);
            
            // Create the startup window
            MainWindow mainWindow = new MainWindow();
            mainWindow.Show();
        }
    
    

    But the automation tree did not change.

  17. syromiatnikov commented on Feb 6, 2025

    @syromiatnikov

    @Tobiidave
    It is too late to do it in the App ctor. And thanks for creating this issue. It helped me to figure out the workaround. We also have a problem with dataitems. It is random, but all or few might be empty sometimes in ItemsControls with item template.
    Use this one in the startup WPF project:

    <ItemGroup>
      <RuntimeHostConfigurationOption Include="Switch.System.Windows.Controls.ItemsControlDoesNotSupportAutomation" Value="True" />
    </ItemGroup>
  18. AlexGoOn commented on Apr 30, 2025

    @AlexGoOn

    Just checking in - any updates on this issue? We've been hearing from a few customers at DevExpress who are running into problems because of this breaking change

  19. danielkornev commented on Jul 15, 2026

    @danielkornev

    This problem seems to be the reason why you can't always reliably obtain info about controls in Autodesk Revit v2026 (which is built using .NET 8) for doing UI automation testing.

    I saw the following problem:

    1. You open Autodeskt Revit 2026 and open last project (.rvt file)
    2. You query UIA for its controls
    3. You see all controls
    4. You switch its Ribbon to a different tab
    5. You query UIA for its controls
    6. You don't see controls of the active tab
    7. You go to Inspect.exe or Accessibility Insights for Windows, you see that controls in second tab are not available via UIA/MSAA

    Your actual expectation is to see them.

    Then, at some point, I've got those controls to appear (absolutely randomly).

    At some point I thought it's because Autodesk Rebvit's team decided to avoid supporting UI automation. But then why some controls would be there, and some not?

    But now, with this bug, and bugs #8800 and #8715 it is clear that this is a WPF on .NET 8 platform bug, not Autodesk Revit's bug.

    My question is, are there any plans to fix this for .NET 8 and up?

  20. lindexi commented on Jul 16, 2026

    @lindexi
    Member

    @danielkornev Given the slow pace on the official side, I've started working on a community release that may include a fix for this. However, this is purely a spare-time effort for me, so development is progressing rather slowly.

    See https://github.com/WpfLab/WpfRuntime

  21. danielkornev commented on Jul 16, 2026

    @danielkornev

    My current experiment is to try to reconstruct UI Automation tree from WPF visual tree...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚧 work in progressInvestigate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions