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
Using a TabControl triggers a TargetInvocationException at App shutdown, when the WPF Control is hosted in a Winform Elementhost #3439
Comments
I investigated this a little bit
Removing these attached properties fixes the issue. In ScrollViewerAssist.cs: When the Winform App with the Elementhost shuts down, the stacktrace indeed shows that the error happens during the cleanup of the WeakEventManager System.Private.CoreLib.dll!System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(object obj, System.Span copyOfArgs, System.Reflection.BindingFlags invokeAttr) Line 176 C# The actual exception is: System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation. The calling thread cannot access.... I am a little clueless how to fix this, since the exception occurs in .net code?! Anybody any idea? |
I also encountered this problem, and this exception did not appear in 4.8 of the MaterialDesignThemes version |
Bug explanation
To reproduce this bug, create a Winform app (tested in .NET 8), add an Elementhost (add from code behind since it is not in the Toolbox anymore...) and host a WPF UserControl which contains a TabControl. This will display fine until you close the app. During shutdown, the TargetInvocationException will be thrown. The call stack is hardly helpful since these are shutdown calls. Other controls are apparently not affected and work fine.
Setting the TabControl Style to x:Null will not trigger the exception anymore, so it is definitely something in the TabControl style.
The "source" object of the exception being found in the WeakEventManager.cs seems to be a Scrollviewer whose parent is a "ColorZone". Hope this hint helps.
Version
4.9.0
The text was updated successfully, but these errors were encountered: