dotnet / dotnet/wpf

WPF Fluent Theme app crashes with CheckBox on multiple UI threads

Open
#11,356 3 comments 1 reaction 0 assignees View on GitHub
Win 11 Theming
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

Hello, I’m facing an issue where a WPF application targeting .NET 9 crashes when using the Fluent UI theme.
In the application, I open separate windows on different UI threads, and each window contains a single CheckBox.
When the second window is opened, the application throws the following exception:

**System.Windows.Markup.XamlParseException:
“The calling thread cannot access this object because a different thread owns it.”**

The issue reproduces only when the CheckBox is checked by default. It appears that the Path control of check mark references shared resources that are not thread-safe. Interestingly, if I apply a custom style to the CheckBox, the issue disappears. However, this is only a workaround and not a proper solution.

I’m attaching a sample project archive that reproduces the issue.

### Reproduction Steps
1. Extract the archive, build and run app
[FluentUIWpfAppWithCheckbox.zip](https://github.com/user-attachments/files/24598065/FluentUIWpfAppWithCheckbox.zip)
2. Click button "New window" twice
### Expected behavior

Second window with CheckBox opens successfully

### Actual behavior

When opening the second window, the application gets the an exception
**System.Windows.Markup.XamlParseException:
“The calling thread cannot access this object because a different thread owns it.”**

To prevent crashing I print exception to debug log

### Regression?

_No response_

### Known Workarounds

Override the default Fluent style for the CheckBox controls in the Window
``

### Impact

_No response_

### Configuration

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.