C
C#16mo ago
Vеrsette

❔ 'System.ExecutionEngineException' occurred in WindowsBase.dll

My WPF project has a UI part that has bindings to DataContext of the Window, and this DataContext is a class that inherits INotifyPropertyChanged and updates it's properties in a while(true) loop in a separate background thread with a small delay. But when I hover my mouse over a certain custom control, it errors out with ExecutionEngineException on it's function. When I remove the control, it errors out the same way on DragMove() of the Window. And the only thing that fixes it is not starting the update thread, which means that the issue must be there, but what could it be?
9 Replies
Vеrsette
Vеrsette16mo ago
Here's the code:
Vеrsette
Vеrsette16mo ago
Gist
Mouse.cs
GitHub Gist: instantly share code, notes, and snippets.
canton7
canton716mo ago
Don't try and interact with UI elements from a background thread. I'm not sure how that would cause an ExecutionEngineException... But UI frameworks by and large are not thread-safe
Vеrsette
Vеrsette16mo ago
I am not directly interacting. It's a PropertyChangedEvent that gets raised by properties in my class that inherits INotifyPropertyChanged The bindings path is the class that I sent, and INotifyPropertyChanged is re-triggering bindings that way Is that the wrong way of doing it? I looked it up, and the first result was this: https://stackoverflow.com/questions/2553333/wpf-databinding-thread-safety
Value changes fired by INotifyPropertyChanged are automatically marshalled back onto the dispatcher. (http://blog.lab49.com/archives/1166)
So I thought that this would be a right way of doing it
Stack Overflow
WPF Databinding thread safety?
Well lets say i have an object that i databind to, it implements INotifyPropertyChanged to tell the GUI when a value has changed... if i trigger this from a different thread than the GUI thread how
canton7
canton716mo ago
(They're marshalled... most of the time. There are some cases where it falls over. And it's really just something it does to try and make the best of a bad situation -- it's not something you should be relying on, really)
Vеrsette
Vеrsette16mo ago
Oh So what's a thread safe way of doing this? I could do a jank workaround by using a DispatcherTimer and just reading the values and updating UI from time to time, but I rather use bindings...
I'm not sure how that would cause an ExecutionEngineException...
It's the first time I encounter this error, so I wonder if it has something to do with the native HID interface library that I'm using, or it's wrapper... I'm not reading the values at the same time though, so the library shouldn't really have any issues
canton7
canton716mo ago
Dispatcher.BeginInvoke / InvokeAsync Ah, there's a native library in there? Yeah that will do it Chances are you've got a pinvoke signature wrong somewhere, and you're corrupting the stack
Vеrsette
Vеrsette16mo ago
I got the source code of both the wrapper and library, so I will check Yes! It ended up being an issue with the wrapper. So annoying when the debugger doesn't quite show you where the issue is... Thanks for the GuraHappy
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.