microsoft / microsoft/WindowsAppSDK

AppInstance.FindOrRegisterForKey throws ArgumentException: The parameter is incorrect

Open
#5,694 4 comments 0 reactions 0 assignees View on GitHub
area-Lifecycle needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

While trying to track down crashes, I put `var keyInstance = AppInstance.FindOrRegisterForKey("main"); ` in a try-catch and found that it's throwing an `ArgumentException` (with message "`The parameter is incorrect.\r\n\r\nThe parameter is incorrect`") for some of my users.

### Steps to reproduce the bug

```
class Program
{
[STAThread]
static void Main()
{
try
{
var keyInstance = AppInstance.FindOrRegisterForKey("main");
if (keyInstance.IsCurrent)
{
keyInstance.Activated += (_, _) => App.HandleAppActivation();
Application.Start(p =>
{
var context = new DispatcherQueueSynchronizationContext(DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
_ = new App();
});
}
else { keyInstance.RedirectActivationToAsync(AppInstance.GetCurrent().GetActivatedEventArgs()).GetAwaiter().GetResult(); }
}
catch (Exception ex) { **log error** }
}
}
```

### Expected behavior

No exception

### Screenshots

_No response_

### NuGet package version

Windows App SDK 1.7.3: 1.7.250606001

### Packaging type

Packaged (MSIX)

### Windows version

Windows 11 version 24H2 LTSC (26100, June Update)

### IDE

Visual Studio 2022

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided Program.Main reproduction and investigate AppInstance.FindOrRegisterForKey("main") using Windows App SDK 1.7.3 on Windows 11 24H2 LTSC. Compare the failing and expected paths, then verify that the call completes without the reported ArgumentException for the packaged MSIX scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.