views:

382

answers:

2

Hello, I have some problems with ChildWindow control, I have created an error window control that is shown after unhandled exception is caught in app.xaml.cs. The problem is when I try to show the error window, sometimes it works fine, but sometimes I get this nasty exception:

Message: Error HRESULT E_FAIL has been returned from a call to a COM component.

Stack Trace: at MS.Internal.XcpImports.CheckHResult(UInt32 hr) at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, Boolean b) at System.Windows.DependencyObject.SetValue(DependencyProperty property, Boolean b) at System.Windows.Controls.Primitives.Popup.set_IsOpen(Boolean value) at System.Windows.Controls.ChildWindow.Show() at FrontEnd.SL.Util.GuiLogger.ShowErrorWindow(ErrorDetails details, ErrorSeverity severity)


the trace you see is inside the Show() method of the ChildWindow.
In another words, my code is:
ErrorWindow errorWin= new ErrorWindow();
errorWin.Show();
where ErrorWindow:ChildWindow

any help is greatly appreciated..

A: 

It seems to me that the use of a ChildWindow control is going to be prone to some problems. What happens if the incumbent VisualTree is in an inconsistent/broken state as result of the exception?

The best chance you have to "handling" an unhandled exception within the bounds of the application would be to completely replace the existing object held by the VisualRoot.

AnthonyWJones
Hello Anthony, You are right, it seems that VisualTree state was indeed broken as a result of an error that was caught. Instead of using .Show() method in these cases, I need to manually add ChildWindow to RootVisual. A bit of a botched job, but what can you do :S
Boris
A: 

This can also happen if there is a problem loading the content of the childwindow. In my case I had specified different namespaces in a usercontrol's code-behind and its xaml, which caused this cryptic error.

Lars Holm Jensen