-
Notifications
You must be signed in to change notification settings - Fork 1.2k
BAML readers in Application.LoadContent() are not protected with locks, resulting in showstopper exceptions #3411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you provide a minimal repro application? Thanks. |
Too busy to create a repro yet but stay tuned. This decade-old post on Stack Overflow illustrates another aspect of the problem. Again, the workaround offered is almost impossible because Application.LoadComponent() is wrapped inside autogenerated InitializeComponent() calls. This strategy is also prone to mystery deadlocks when deep objects in the XAML graph access dependency properties on objects belonging to other threads. You are not doing something wrong. MSDN is wrong. Application.LoadComponent is not actually thread safe. This is a bug in WPF, in my opinion. The problem is that whenever Application.LoadComponent loads a "Part" from a "Package" it:
You have two threads calling Application.LoadComponent to load the same part at the same time. The MSDN documentation says this is ok, but what is happening is:
The workaround for the bug is to wrap all calls to Application.LoadComponent inside a lock(). Your lock object can be created thusly in your App.cs or elsewhere (your choice):
Then your LoadComponent call looks like this:
|
Fixed by @SamBent. |
BAML readers in Application.LoadContent() are not being properly protected with locks. This prevents windows with complex content from opening simultaneously on multiple separate threads because they crash with unhandled exceptions. It is almost impossibly difficult to lock this functionality at the application level. This bug is perfectly easy to demonstrate. This applies to any and all versions of WPF.
The text was updated successfully, but these errors were encountered: