InputInjection InitializeGamepadInjection method causes app hang + crash intermittently
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:
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
Hi @MoodieG , can you please information about version of WinUI you are using?
The reproducible sample I shared is using a simple console application. However, the actual application is using Blazor Hybrid with WPF.
It does not crash on my configuration (Windows 10 22H2, WinUI 3 Desktop app as Admin (Manifest), Windows App SDK 1.7.250401001)
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
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 Since it didn't reproduced by others, can you please attach a complete repro project as zip?