microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

InputInjection InitializeGamepadInjection method causes app hang + crash intermittently

Open MoodieG opened this issue 2 months ago • 4 comments

Describe the bug

Hey, I have been using InputInjector in my application for over a year now with no issues. However, it has been the source of application hangs and crashes recently when initializing gamepad injection. I am suspecting the culprit to be a windows update.

I was able to reproduce the issue in a simple console application.

Why is this important?

The gamepad input injector is a core component of our application, and users are experiencing crashes 20-40% of the times when the input injector is initialized.

Steps to reproduce the bug

Environment

Windows version: 25H2 (OS Build 26200.6899 Windows is in developer mode

C# project file

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0-windows10.0.22000.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

Program.cs file

namespace InputInjector;

using Windows.Gaming.Input;
using Windows.UI.Input.Preview.Injection;

internal class Program
{
    static async Task Main(string[] args)
    {
        var inputInjector = InputInjector.TryCreate();

        for (int i = 0; i < 100; i++)
        {
            inputInjector.InitializeGamepadInjection();
            inputInjector.InjectGamepadInput(new InjectedInputGamepadInfo { Buttons = GamepadButtons.A });
            inputInjector.UninitializeGamepadInjection();

            Console.WriteLine($"Attempt {i + 1} succeeded.");
            await Task.Delay(1000);
        }

        Console.WriteLine("Done");
    }
}

Actual behavior

Output

Running the application as administrator I get the following output:

Image

The hang and crash occurred after 15 attempts in this case with no error information.

Expected behavior

No hang or crash

Screenshots

No response

NuGet package version

None

Windows version

25H2 26200.6899

Additional context

Console app framework is net8.0-windows10.0.22000.0

MoodieG avatar Oct 29 '25 18:10 MoodieG

Hi @MoodieG , can you please information about version of WinUI you are using?

snigdha011997 avatar Oct 30 '25 15:10 snigdha011997

The reproducible sample I shared is using a simple console application. However, the actual application is using Blazor Hybrid with WPF.

MoodieG avatar Oct 30 '25 16:10 MoodieG

It does not crash on my configuration (Windows 10 22H2, WinUI 3 Desktop app as Admin (Manifest), Windows App SDK 1.7.250401001)

castorix avatar Oct 30 '25 17:10 castorix

Hi @MoodieG , the above information is not sufficient for us to reproduce the issue, we need minimal repro project and its related details to investigate further

snigdha011997 avatar Dec 12 '25 09:12 snigdha011997

Hey @snigdha011997 , my original post shares the csproj file along with the program and environment details. What other details can I share?

This bug is related to using Windows.UI.Input.Preview.Injection APIs. Let me know if this is the wrong repo to post this issue. I posted it here because I found other users post similar issues regarding that here.

MoodieG avatar Dec 12 '25 18:12 MoodieG

@MoodieG Since it didn't reproduced by others, can you please attach a complete repro project as zip?

ayushjai19 avatar Dec 18 '25 15:12 ayushjai19