3

When I click shaky/nervous/hammering with the pen on the ComboBox, click on the items, move the pen while clicking... after 5 or 10 minutes the control stops working.
Then I can open the ComboBox, can click on an item, the item gets highlighted, but nothing happens: The ComboBox does not close and no click event gets fired.
The same error happens with a ContextMenu. And when the error occurs then all ComboBoxes and all menus does not work anymore. It occurs when i click with the pen or with my finger, the mouse works fine even when the controls are no more usable with pen or finger.

In normal usage, this happens about 5 times per working day, very annoying for my users. You need some "patience" to get the error reproduced, maybe it takes you more than 10 minutes... but it DOES happen.

I have made a simple test app with one ComboBox and one button with a ContextMenu, you can re-produce the error with it.
Target framework of my app is 4.6.1, compiled with VS2015. My app works fine with Windows 8.1 and Windows 10 Anniversary, with .NET 4.6.1 and 4.6.2.

The error happens on Microsoft Surface Pro 3 and Pro 4 with
- Windows 10 Creators Update (.NET 4.7 included)
- Windows 10 Anniversary Update and .NET 4.7 installed
- Windows 8.1 and .NET 4.7 installed
- Windows 10 Anniversary Update (.NET 4.6.2) and KB4034658 installed !!!

For the 1st three scenarios, i found out how to block Creators Update and .NET 4.7 from getting installed by Windows Update, at least for about the next 6 months.
But with the August 2017 Cumulative Update KB4034658, the current options for my users with Windows 10 are either to live with the errors or to completely deactivate all Windows Updates.

Here is the code of my test app:

MainWindow.xaml:

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DotNet47ComboBoxAndMenuError"
        mc:Ignorable="d"
        Title="" Height="900" Width="715" WindowStartupLocation="Manual" WindowState="Maximized">
    <Grid>
        <WrapPanel>
            <ComboBox FontSize="16" Width="150">
                <ComboBoxItem>ComboBoxItem 1</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 2</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 3</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 4</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 5</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 6</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 7</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 8</ComboBoxItem>
                <ComboBoxItem>ComboBoxItem 9</ComboBoxItem>
            </ComboBox>
            <Button x:Name="btnMenu" Content="MENU" FontSize="16" Margin="100,0,0,0">
                <Button.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="MenuItem 1"></MenuItem>
                        <MenuItem Header="MenuItem 2"></MenuItem>
                        <MenuItem Header="MenuItem 3"></MenuItem>
                        <MenuItem Header="MenuItem 4"></MenuItem>
                        <MenuItem Header="MenuItem 5"></MenuItem>
                        <MenuItem Header="MenuItem 6"></MenuItem>
                        <MenuItem Header="MenuItem 7"></MenuItem>
                        <MenuItem Header="MenuItem 8"></MenuItem>
                        <MenuItem Header="MenuItem 9"></MenuItem>
                    </ContextMenu>
                </Button.ContextMenu>
            </Button>
        </WrapPanel>
    </Grid>
</Window>

Only XAML, absolutely no code in my test app.

My users also report that occasionally clicking on buttons does nothing in dialog windows. When this happens, they only can click the upper right close button; drop-downs and menus don't work anymore in the main window as described above: they need to close and restart the app. Have not reproduced this with a sample, I guess it's the same error.

Also, my app occasionally crashes with Windows 10 Creators Update or .NET 4.7, probably also with KB4034658. Unfortunately, I cannot tell when these crashes happen, but I suspect they are related to the above-described issue in some way.

Sample crash info from the windows event log:

      <Category>0</Category>
      <ComputerName>DESKTOP-XXXXXX</ComputerName>
      <EventCode>1026</EventCode>
      <EventIdentifier>1026</EventIdentifier>
      <EventType>1</EventType>
      <InsertionStrings>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IndexOutOfRangeException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Insert(System.__Canon, System.__Canon, Boolean)
   at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePackets(Int32, Int32[], Int32)
   at System.Windows.Input.PenThreadWorker.FlushCache(Boolean)
   at System.Windows.Input.PenThreadWorker.FireEvent(System.Windows.Input.PenContext, Int32, Int32, Int32, Int32, IntPtr)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

</InsertionStrings>
      <Logfile>Application</Logfile>
      <Message>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IndexOutOfRangeException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Insert(System.__Canon, System.__Canon, Boolean)
   at System.Windows.Input.StylusWisp.WispLogic.CoalesceAndQueueStylusEvent(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePackets(Int32, Int32[], Int32)
   at System.Windows.Input.PenThreadWorker.FlushCache(Boolean)
   at System.Windows.Input.PenThreadWorker.FireEvent(System.Windows.Input.PenContext, Int32, Int32, Int32, Int32, IntPtr)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Message>
      <RecordNumber>250</RecordNumber>
      <SourceName>.NET Runtime</SourceName>
      <TimeGenerated>8/1/2017 2:10:56 PM</TimeGenerated>
      <TimeWritten>8/1/2017 2:10:56 PM</TimeWritten>
      <Type>Error</Type>

2nd sample:

      <Category>0</Category>
      <ComputerName>DESKTOP-XXXXXX</ComputerName>
      <EventCode>1026</EventCode>
      <EventIdentifier>1026</EventIdentifier>
      <EventType>1</EventType>
      <InsertionStrings>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FindEntry(System.__Canon)
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryGetValue(System.__Canon, System.__Canon ByRef)
   at System.Windows.Input.StylusLogic.ProcessInputReport(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePenOutOfRange(Int32, Int32)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

</InsertionStrings>
      <Logfile>Application</Logfile>
      <Message>Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentNullException
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].FindEntry(System.__Canon)
   at System.Collections.Generic.Dictionary`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].TryGetValue(System.__Canon, System.__Canon ByRef)
   at System.Windows.Input.StylusLogic.ProcessInputReport(System.Windows.Input.RawStylusInputReport)
   at System.Windows.Input.PenContext.FirePenOutOfRange(Int32, Int32)
   at System.Windows.Input.PenThreadWorker.ThreadProc()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()
</Message>
      <RecordNumber>534</RecordNumber>
      <SourceName>.NET Runtime</SourceName>
      <TimeGenerated>7/31/2017 1:13:39 PM</TimeGenerated>
      <TimeWritten>7/31/2017 1:13:39 PM</TimeWritten>
      <Type>Error</Type>

I have reported the errors at https://connect.microsoft.com/VisualStudio and https://github.com/Microsoft/dotnet/issues

I don't expect to get a solution for this error, but any idea is welcome.

I wonder if the error occurs only on MS Surface. I found no other post regarding this error, so i would think so. No good chance to get it fixed soon... WPF and Surface - too exotic.

With this post, i hope that a few people with a Surface will re-produce the error and also report the bug to Microsoft, to increase the chance that it gets fixed by MS asap. Also, i would like to know whether this error occurs only on MS Surface Tablets or also on other tablets, maybe only on High-DPI tablets?

Andy
  • 31
  • 5
  • As a temporary workaround for your users, can you find some way to force the app to run under 4.6.2, perhaps [Force an application to run under specific .NET runtime version?](https://stackoverflow.com/q/2046089/1115360) helps. – Andrew Morton Aug 16 '17 at 20:01
  • 4.7 is installed as replacement for 4.x, not side by side. It's not possible to force 4.6.2 when 4.7 is installed. Also, this would not help with the "Security" KB4034658. But thank you for your suggestion! I tried my test app targeting .NET 3.5. In a 1st test the described error does not occur.... but my app uses 3rd party components only available for 4.x, would need to change many code, and don't know whether then all works fine (maybe other errors in 3.5), and can't be sure that another "Security" update introduces the error also to 3.5 – Andy Aug 18 '17 at 18:23
  • I suppose that would have been too simple. Does the error still happen if you have no code for the menu? If not, is there a specific line of code which causes the error? I found [something](https://connect.microsoft.com/VisualStudio/feedback/details/260873/generic-methods-inlined-incorrectly-by-jit) regarding a problem with System.__Canon where a release build showed a problem but a debug build did not, so maybe you could test a debug build. – Andrew Morton Aug 18 '17 at 19:20
  • ... also [Strange System.__Canon exception](https://stackoverflow.com/questions/16854393/strange-system-canon-exception) has an explanation. – Andrew Morton Aug 18 '17 at 19:26
  • The error happens in Release and Debug build. It makes not really fun to make right click with a Pen, but i removed the menu button code... error still happens with absolutely no code. Yes, it sounds too simple, and that's why i fear that no one will even try to verify my reported error, most probably think i make a joke (in best case). – Andy Aug 18 '17 at 22:09
  • We are having application freeze issues in our touch WPF application. I have found a very similar error like yours (searching CoalesceAndQueueStylusEvent only brings up this page). Our users are working with Windows 8.1 and Windows 10 tablets with .NET Framework 4.7 installed. So I'm currently also looking into that direction for further testing. I'll keep you informed. – Bruno V Aug 31 '17 at 07:29
  • @Bruno: Does your users work with MS Surface tablets or others? I don't think MS follows errors reported on stackoverflow. If you do also have same or similar issues, please join on existing error reports at https://connect.microsoft.com/VisualStudio/Feedback for ex. #3139096, #3139101, #3139882 or create a new one. – Andy Aug 31 '17 at 12:32
  • The issue occurs on both Dell and Surface tablets with the .NET Framework 4.7 installed. I have added my feedback on the last issue because it resembles most to mine: [3139882](https://connect.microsoft.com/VisualStudio/Feedback/Details/3139882) – Bruno V Sep 01 '17 at 09:08
  • @Andy: I wanted to make sure it had nothing to do with our application so I tested yours on a Dell tablet and I was able to simulate the problem. After about a minute of tapping the controls, the ComboBox dropdown and Menu still open, but no other item can be selected. I guess you can cross the Surface of your list :-). – Bruno V Sep 01 '17 at 11:50
  • Thank you for testing my sample on the Dell tablet! Good to know for me that the error occurs also on other tablets. – Andy Sep 01 '17 at 13:47
  • Have you tried upgrading to .NET Framework 4.7.1? It seems to solve our issue. – Bruno V Dec 13 '17 at 10:17
  • Yes, 4.7.1 solves this issue for Creators April and Anniversary update. The November Cumulative update solves it finally also for the Creators Fall update. I actually try to prevent the Fall update from getting installed – Andy Dec 13 '17 at 16:05

2 Answers2

0

We have found a workaround but it also has some disadvantages. When disabling the RealTimeStylus at application startup, we cannot reproduce the issue anymore.

However, disabling the RealTimeStylus also disables ScrollViewer swiping using touch. It might also influence the usage of a stylus, I was not able to test this.

While this solution is not optimal, it might be sufficient for your case (or at least be a starting point).

    public static void DisableWPFTabletSupport()
    {
        // Get a collection of the tablet devices for this window.  
        TabletDeviceCollection devices = System.Windows.Input.Tablet.TabletDevices;

        if (devices.Count > 0)
        {
            // Get the Type of InputManager.
            Type inputManagerType = typeof(System.Windows.Input.InputManager);

            // Call the StylusLogic method on the InputManager.Current instance.
            object stylusLogic = inputManagerType.InvokeMember("StylusLogic",
                        BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                        null, InputManager.Current, null);

            if (stylusLogic != null)
            {
                //  Get the type of the device class.
                Type devicesType = devices.GetType();

                // Loop until there are no more devices to remove.
                int count = devices.Count + 1;

                while (devices.Count > 0)
                {
                    // Remove the first tablet device in the devices collection.
                    devicesType.InvokeMember("HandleTabletRemoved", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, devices, new object[] { (uint)0 });

                    count--;

                    if (devices.Count != count)
                    {
                        throw new Win32Exception("Unable to remove real-time stylus support.");
                    }
                }
            }
        }
    }
Bruno V
  • 1,721
  • 1
  • 14
  • 32
  • This "hack" seems to solve the combobox and menu issues. It breaks touch scroll for WPF controls (ScrollViewer, ComboBox, DataGrid, ...?) but this might be the minor problem for my users. I give this workaround a try. Thank you!!! – Andy Sep 05 '17 at 21:18
  • I'm glad I could help. Unfortunately for us this fix is not sufficient, we need to maintain ScrollViewer touch scrolling. I've created a separate question to get this fixed: https://stackoverflow.com/q/46049673/3357566 – Bruno V Sep 06 '17 at 06:13
  • I was optimistic, writing on InkCanvas worked, touch scroll in CEF browser worked... but the eraser button does not work on the InkCanvas. – Andy Sep 06 '17 at 15:27
0

this question is a bit back, but I have an explanation for the "no longer responding to the GUI".

If an item is not 100% visible in the listview (deposited) and you execute a click, then the listview scrolls the item fully visible first. Everything works with the mouse. But the TouchUp event fires just before scrolling. And that's exactly where the mistake happens. I bypass this by waiting for the "Click-Event", no matter if touch or mouse, 10ms and only then execute my action. Thus, the error is fixed with me.