Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF Touch Event Fails When Using ManagementEventWatcher for WMI Changes #9752

Open
lindexi opened this issue Sep 10, 2024 · 0 comments
Open
Labels
Bug Product bug (most likely)

Comments

@lindexi
Copy link
Contributor

lindexi commented Sep 10, 2024

Description

When using ManagementEventWatcher to listen for WMI changes in a WPF application, the touch functionality becomes unresponsive.

Reproduction Steps

  1. Install the System.Management library to use WqlEventQuery for monitoring WMI changes.
  2. Attach a breakpoint to the TouchDown event to log information.

The complete code for reproduction is as follows:

    public MainWindow()
    {
        InitializeComponent();

        AppDomain.CurrentDomain.FirstChanceException += (sender, args) =>
        {
            Debug.WriteLine(args.Exception);
        };

        WqlEventQuery insertQuery =
            new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'");
        ManagementEventWatcher insertWatcher = new ManagementEventWatcher(insertQuery);
        insertWatcher.Start(); // When the line `insertWatcher.Start();` is commented out, touching the window hits the breakpoint in the `MainWindow_TouchDown` method. However, after executing `insertWatcher.Start();`, touching the window does not hit the `MainWindow_TouchDown` method.

        TouchDown += MainWindow_TouchDown;
    }

    private void MainWindow_TouchDown(object? sender, TouchEventArgs e)
    {
        Debugger.Break(); // Never hit
    }

When the line insertWatcher.Start(); is commented out, touching the window hits the breakpoint in the MainWindow_TouchDown method. However, after executing insertWatcher.Start();, touching the window does not hit the MainWindow_TouchDown method.

Additionally, a FirstChanceException is thrown, with the following exception details:

System.InvalidCastException: Interface not registered

   at MS.Win32.Penimc.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)

Here is the content of the csproj file used in my code:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net9.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Management" Version="6.0.2"/>
  </ItemGroup>
</Project>

I have uploaded a minimal reproduction project to GitHub. You can clone the project to reproduce the issue.

Expected behavior

It can work well and receive the touch event

Actual behavior

The TouchDown event never be raised.

This issues only happend in .NET Core not the .NET Framework.

Regression?

No response

Known Workarounds

The touch event can be raised after open the WM_Pointer support, because the PointerLogic do not need the COM.

Impact

No response

Configuration

OS version: Windows 11 23H2 22631.4037

Other information

Reference: #9706

We has the similar exception.

@lindexi lindexi added the Bug Product bug (most likely) label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product bug (most likely)
Projects
None yet
Development

No branches or pull requests

1 participant