2

DotNet 4.0 throws a runtime ComException when a MenuItem, which was previously visible, becomes hidden. When switching to DotNet 3.5 the Exception is no longer thrown.

Setup

  • Create new WPF DotNet 4.0 project
  • Add the following XAML code to the default Grid

    <Menu Height="23"> <MenuItem Header="Item1"> <MenuItem Header="SubItem1"/> </MenuItem> <MenuItem Header="Item2"> <MenuItem Header="SubItem2" /> </MenuItem> </Menu>

  • Make sure that "Common Language Runtime Exceptions" is checked under Debug->Exceptions

  • Run the application and click on the first menu item, then click on the second menu item, then move the mouse pointer back to the first menu item

Does anyone know of a specific way to workaround this problem?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Fortmann
  • 433
  • 6
  • 20
  • Furthermore, I experienced similar exceptions with other WPF controls (e.g. Combobox) – Fortmann Aug 29 '12 at 13:34
  • Apparently, any element that is involved with WPF UI Automation is susceptible to this exception. Additional simple tests with other controls (e.g. ComboBox) also cause the exception. – Fortmann Aug 30 '12 at 17:08
  • Also tried applying DotNet 4.0 update [NDP40-KB2468871-v2], but to no avail – Fortmann Aug 31 '12 at 07:56
  • More strange behaviour : it seems this problem may be related to the state of the runtime? / other software?... Yesterday I ran *exactly* the same test project, but did not experience the error at all. Today I open the test project and the exception is thrown again. Could this be related to DotNet services? – Fortmann Sep 04 '12 at 11:47

2 Answers2

0

By invoking the relevant controls from code, before the user has a chance to do so from the GUI, prevents the UI Automation exception for being thrown. Why?

e.g.

i1.IsSubmenuOpen = false;
i2.IsSubmenuOpen = true;
i2.IsSubmenuOpen = false;
i1.IsSubmenuOpen = true;
Fortmann
  • 433
  • 6
  • 20
0

A set of Windows 7 update fixed this problem. Bizarre!

I have been running windows 7 (64bit) without updates for approximately 1 year now. After applying a large set of cumulative updates the problem went away.

Fortmann
  • 433
  • 6
  • 20