microsoft / microsoft/WindowsAppSDK

AppInstance.UnregisterKey() causes a failfast crash when called on a different thread than FindOrRegisterForKey(...) was called from

Open
#6,447 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Lifecycle needs-triage
Dominant language
C++
Stars
4.7k
Forks
471
Avg merge
3d 13h
Merged PRs (30d)
28

Description

### Describe the bug

When I call AppInstance.UnregisterKey() from a different thread than FindOrRegisterForKey(...) was called from, for me it consistently immediately crashes the process with a `0xc0000409` code. It seems to happen when trying to reset a mutex, `m_keyCreationMutexLock`, inside `UnregisterKey()`.

If this is intended/expected behavior, it should at least be called out in the documentation for `FindOrRegisterForKey` and `UnregisterKey`. This was very frustrating to debug.

### Steps to reproduce the bug

Minimal reproduction:
`

AppInstance.FindOrRegisterForKey("key");
Thread.Sleep(3000);
new Thread(() =>
{
AppInstance.GetCurrent().UnregisterKey();
}).Start();`

### Expected behavior

The key will be registered and unregistered, without crashing the process.

### Screenshots

_No response_

### NuGet package version

2.0.1

### Packaging type

Packaged (MSIX)

### Windows version

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

### IDE

Other

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproduction using AppInstance.FindOrRegisterForKey and AppInstance.UnregisterKey, then investigate the cross-thread call and the m_keyCreationMutexLock reset described in the report. Done means the key can be registered and unregistered from the shown threads without a process crash, or the thread requirement is clearly documented for both APIs.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.