Random crash in WPF application : "Invalid index at MS.Win32.UnsafeNativeMethods.GetWindowText(...)" - c#

We experience following crash at random moments in our WPF application:
Invalid index at MS.Win32.UnsafeNativeMethods.GetWindowText(HandleRef hWnd, StringBuilder lpString, Int32 nMaxCount)
at System.Windows.Automation.Peers.WindowAutomationPeer.GetNameCore()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.ContextLayoutManager.fireAutomationEvents()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
Most of the time the crash occurs on any call to "ShowDialog()" in the WPF code, sometimes also on other calls (unclear which exactly, the stack trace just mentions the top-level "Application.Run()")
The problem starts occurring randomly after having accessed some javascript code in a CefSharp embedded browser component, which adds WebRTC streaming functionality to the WPF application. The crashes stopped occurring as soon as we replaced the CefSharp component with Microsofts WebView2 component.
On a few occasions in the past we encountered the exact same random crash when our WPF application was running alongside 2 other third party applications :
a "TabletInputService", part of Smart Technologies whiteboard software
a screen capture driver ("VHScrCap" of Split Media Labs)
At that moment we found that the crash even occurred in a dummy WPF test application which contained nothing but 1 "ShowDialog()" call. This lead us to the conclusion that we could change nothing in our WPF application code to avoid the crashes. Only "solution" was to replace above screen capture driver with the DirectShow "screen-capture-recorder"
My question is : what could be the root cause of this window handle corruption, and what could we do to avoid the resulting crashes in a WPF application?

I hope I found the cause of this issue. I again encountered the same crash, but again under different conditions: after calling VideoCapturer.EnumerateDevices() on the OpenTok.NET Nuget library, the crash started occurring when expanding any combobox in any WPF modal dialog.
Now it looks like the instability is caused by not specifying the Title property of a WPF window. In our application most of the dialogs are headerless (WindowStyle="None"), as we design our own window headers, so setting the Title property is unnecessary/irrelevant. This must confuse the Win32 API call "GetWindowText()", resulting in a nasty crash. Seems like a serious WindowOS/WPF bug to me.
After scanning our full application source code and specifying a (dummy) Title for each and every dialog, the crash stopped occurring (at least for now).
I have now also reviewed the code of the "dummy WPF test application" mentioned earlier, which could reproducibly trigger the crash under certain conditions. And indeed, the code was :
Window dummy = new Window();
dummy.ShowDialog();
Today I no longer can reproduce the error condition (triggered by third party applications) but it now seems likely that adding dummy.Title = 'Dummy'; to the test code above would have avoided the crash.

Related

WPF COMException Crashes Application At Startup (Started Today)

I have just today started seeing this Exception out in the wild on application launch with an app that has been in production for 3 years.
System.TypeInitializationException: The type initializer for 'MS.Win32.Penimc.UnsafeNativeMethods' threw an exception. ---> System.Runtime.InteropServices.COMException: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
at MS.Win32.Penimc.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at MS.Win32.Penimc.UnsafeNativeMethods.CreatePimcManager()
at MS.Win32.Penimc.UnsafeNativeMethods..cctor()
--- End of inner exception stack trace ---
at MS.Win32.Penimc.UnsafeNativeMethods.CreateResetEvent(IntPtr& handle)
at System.Windows.Input.PenThreadWorker..ctor()
at System.Windows.Input.PenThreadPool.GetPenThreadForPenContextHelper(PenContext penContext)
at System.Windows.Input.PenThreadPool.GetPenThreadForPenContext(PenContext penContext)
at System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTabletsImpl()
at System.Windows.Input.StylusWisp.WispTabletDeviceCollection.UpdateTablets()
at System.Windows.Input.StylusWisp.WispTabletDeviceCollection..ctor()
at System.Windows.Input.StylusWisp.WispLogic.get_WispTabletDevices()
at System.Windows.Input.StylusWisp.WispLogic.RegisterHwndForInput(InputManager inputManager, PresentationSource inputSource)
at System.Windows.Interop.HwndStylusInputProvider..ctor(HwndSource source)
at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
at System.Windows.Window.CreateSourceWindowDuringShow()
at System.Windows.Window.SafeCreateWindowDuringShow()
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at APSSSentinel.App.Main()
Apparently, some developers using VS2017 who got a Windows update that installed .NET 4.7 have been getting this crash as well, it appears the recommended workaround for now is to turn touch support off.
https://developercommunity.visualstudio.com/content/problem/55303/visual-studio-may-terminate-unexpectedly-when-runn.html
With my application, this is not ideal. Has anyone else run into this, and found any other sort of workaround?
Update: Microsoft has now fixed this problem in a manual update (as noted by Jürgen), personally I will stick with the workaround until the fix is in the automatic update because it would be a lot of work to make every user install a manual update.
This is obviously a bug in .Net 4.7 that affects Windows 7 and 8/8.1 systems that have a touch input device. Therefore one can hope that Microsoft addresses this in a future update. Meanwhile the only way to retain full functionality is by uninstalling and hiding the update.
Other option is disabling the stylys and touch support either in app.config (like in your link) or in the code if the app is compiled with 4.6 or newer. You didn't specify why that is not ideal but I assume those features are needed? Notice that the disabling doesn't mean that every app is unusable with touch devices, but rather that they only use features that are accessible with a mouse. Update: Apparently touch device users without a mouse will have trouble using UI that requires scrolling.
Here's the code examples for those who come here seeking quick fix:
In App.config (works with apps compiled with any framework version)
<configuration>
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true" />
</runtime>
</configuration>
In code (when compiled with .Net Framework >= 4.6)
protected override void OnStartup(StartupEventArgs e)
{
AppContext.SetSwitch("Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport", true);
base.OnStartup(e);
}
Microsoft has fixed the issue with .NET 4.7 meanwhile, see
https://support.microsoft.com/en-US/help/4033488/comexception-error-from-wpf-applications-after-the-net-framework-4-7-i

WPF application crashes when connected via Teamviewer

I have a problem when connecting with teamviewer to the device on which my WPF appliction is running. If this connection is made, my WPF application crashes with the following exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ComponentModel.Win32Exception: Cannot create a file when that file already exists
at MS.Win32.UnsafeNativeMethods.GetWindowText(HandleRef hWnd, StringBuilder lpString, Int32 nMaxCount)
at System.Windows.Automation.Peers.WindowAutomationPeer.GetNameCore()
at System.Windows.Automation.Peers.AutomationPeer.UpdateSubtree()
at System.Windows.ContextLayoutManager.fireAutomationEvents()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
This problem seems to be the same as described
here.
In the comments on this question, usage of the clipboard is mentioned as a possible cause of this problem. But my WPF application does not use the clipboard.
I hope someone can help me finding the cause of this exception.
I just fixed this problem myself. It was caused by an empty title of the MainWindow. After setting it, the problem is fixed.

"Object reference not set to an instance of an object" in PresentationFramework with Live Shaping

I'm getting a null reference in the PresentationFramework on my LifeShaping filtering:
The stack trace isn't giving me much clue:
at System.Windows.Data.ListCollectionView.RestoreLiveShaping()
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Window.ShowDialog()
at MVVMSeaCores.AppWindowManager.ShowDialog(Object rootModel, Object context, IDictionary`2 settings)
That last line is the dialog call that shows the UX that holds the checkbox bound to ShowOnGraph.
I'm setting the live-shaping like this, based off a boolean property "ShowOnGraph":
KPIBarsView = new CollectionViewSource { Source = KPIBars }.View;
KPIBarsView.Filter = FilterBars;
//grouping
if (KPIBarsView != null && KPIBarsView.CanGroup == true)
{
KPIBarsView.GroupDescriptions.Clear();
KPIBarsView.GroupDescriptions.Add(new PropertyGroupDescription("KPIViewModel.ContextViewModel"));
}
//Live Filtering
ICollectionViewLiveShaping KPIBarsViewLiveShaping = KPIBarsView as ICollectionViewLiveShaping;
if (KPIBarsViewLiveShaping.CanChangeLiveFiltering)
{
KPIBarsViewLiveShaping.LiveFilteringProperties.Add("ShowOnGraph");
KPIBarsViewLiveShaping.IsLiveFiltering = true;
}
Items are filtered as I'd expect when ShowOnGraphis set to false. However, as soon as I try and unfilter anything with ShowOnGraph=true I get this exception.
This is not a duplicate of "What's a null reference exception". I know what a null reference exception is. But in this case, the null reference is in the Presentation Framework, in System.Windows.Data. I've got no idea what's null, why (the list doesn't contain any null entries, the filter Property is a bool and cannot be null).
The null object isn't in my code, and isn't available for me to debug. All I get in the debugger is where in the dispatch it was when this occured. In one case, it's in the dialog that contains the list where I'm setting it to true:
There's nothing null.
I'll just make a button to set a ShowOnGraph=false, and see where the exception occurs there.
Edit: Yep, it occurs "nowhere". Just opens up on a blank "Break mode" page with no content or indication of where the error occurred.
johnDisplayClass's comment is very helpful.
Something that worked for me: was if i also kept a member reference to each new CollectionViewSource as well as its CollectionView. This kept my live shaping and filtering working. Just this alone solved the same null ref that the OP was experiencing.
Another way to prevent this null exception is to set IsLiveSorting / IsLiveGrouping / IsLiveFiltering to false before the CollectionViewSource or CollectionView been garbage collected.
Found a solution!
I was creating the view directly (rather than using the default view, because I in had two views driven from this collection:
KPIBarsView = new CollectionViewSource { Source = KPIBars }.View;
Which I did after reading this: http://social.technet.microsoft.com/wiki/contents/articles/26673.wpf-collectionview-tips.aspx
and the following SA questions:
WPF Multiple CollectionView with different filters on same collection
WPF CollectionViewSource Multiple Views?
However, I tried just creating a new collection, populating it with the same items and using:
KPIBarsView = CollectionViewSource.GetDefaultView(KPIBars);
solved the problem. Hope this is helpful for anyone else who stumbles upon it.
What I recommend is that you set yourself up to debug the Microsoft dll's from within your solution
https://msdn.microsoft.com/en-us/library/cc667410.aspx
Then make sure your debug settings have all of the possible exception types checked, then when you run your app again and break on the exception, you'll get a full stack trace that could help you work out the isse.

Only while running on VS 2010: COMException: Catastrophic Failure: Error Code: -2147418113

I am stuck with this error: while trying to use an old DLL in .Net Framework 4.0
If I change project target type to 3.5 then no error appears.
The strange is that all this happen Only while running inside VS 2010. If I run the executable from Windows Explorer, no problem occurs in 3.5 and 4.0.
Seems like some bug in vshost? VS 2010 Express, or .net framework?
UPDATE: This BUG only happen on WPF Standalone Application, if a change it to XBAP WPF I can use the dll without bigger problems, only a message telling it could no stop debugging.
I will leave this question open here, waiting to see if there is some progress on the connect.microsoft.com about this ticket.
Is there some way to make my .net4 app.config load this specific dll(CobreBemX.dll) using the .net 3.5 ?
I think this is some bug then i submitted it to https://connect.microsoft.com/VisualStudio/feedback/details/636697/comexception-was-unhandled-catastrophic-failure
Here is the code where it throws that COMException:
//Cria instância do objeto CobreBemX
CobreBemX.ContaCorrente _CobreBemX = new CobreBemX.ContaCorrenteClass();
//Monta arquivo de licença de teste para banco 001 carteira 18
_CobreBemX.ArquivoLicenca = #"C:\CobreBemX\Exemplos\Licencas\237-09.conf"; // THIS LINES CAUSES THE PROBLEM ON .NET 4.0 IF I CHANGE TARGET FRAMEWORK TO 3.5 NO PROBLEM HAPPENS
This is the stack trace:
System.Runtime.InteropServices.COMException was unhandled
Message=Falha catastrófica
Source=CobreBemX.ContaCorrente
ErrorCode=-2147418113
StackTrace:
at CobreBemX.ContaCorrenteClass.set_ArquivoLicenca(String Value)
at EmissorBoletosWindows.MainWindow.button1_Click(Object sender, RoutedEventArgs e) in C:\inetpub\wwwroot\CRM\Cobranca\EmissorBoletosWindows\EmissorBoletosWindows\MainWindow.xaml.cs:line 90
at EmissorBoletosWindows.MainWindow.Window_Loaded(Object sender, RoutedEventArgs e) in C:\inetpub\wwwroot\CRM\Cobranca\EmissorBoletosWindows\EmissorBoletosWindows\MainWindow.xaml.cs:line 39
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.Resize(ICompositionTarget resizedCompositionTarget)
at System.Windows.Interop.HwndTarget.OnResize()
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Window.ShowHelper(Object booleanBox)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at EmissorBoletosWindows.App.Main() in C:\inetpub\wwwroot\CRM\Cobranca\EmissorBoletosWindows\EmissorBoletosWindows\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
If you examine the top of the stack, the method suggests the library is performing some software licensing processing. My guess (and it is a guess) is that the library is using the executable's name and path to locate the license and, because the application is running through VSHost, this is failing causing an error which is expressed as a COM exception.
The fact it works fine outside of VSHost would lend weight to this. You could use a tool such as FileMon to possibly see where it is tripping up.
For now this has no solution other than use XBAP

WPF application crash

I am working on a WPF application with a TabControl (3 tabs with textBlocks, labels and dataGrids). The application auto-refreshes the data on these tabs using background threads. Everything works great except for the fact that if I switch tabs when one of the background processes fires, it throws an "Object reference not set to the instance of an object" error and crashes the application. I have set up DispatcherUnhandledException to handle any unhandled exception on the UI thread. The stack trace does not provide much data other than stating the fact that the error is coming from the TabControl and possibly the objects associated with the selected tab. My question is this: Is their inherent issues with the WPF TabControl that may cause this behavior? I have, as previously mentioned, set up as much error handling as I know how but all that is received is the "Object reference..." error.
Stack trace:
at System.Windows.Controls.ItemContainerGenerator.MoveToPosition(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem, GeneratorState& state)
at System.Windows.Controls.ItemContainerGenerator.Generator..ctor(ItemContainerGenerator factory, GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.StartAt(GeneratorPosition position, GeneratorDirection direction, Boolean allowStartAtRealizedItem)
at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
at Microsoft.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(Size constraint) in C:\dd\WPF_1\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\Primitives\DataGridRowsPresenter.cs:line 118
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at salesforceConnect.App.Main() in C:\Users\jfeltis\Documents\Expression\Blend 3\Projects\salesforceConnect\salesforceConnect\obj\Debug\App.g.cs:line 0
All of this is gibberish to me. Can someone smarter than myself take a look and, hopefully, give me some direction? Thank you.
Try putting a breakpoint in your SelectionChanged event handler and click on a different tab as soon as the app starts. Do you have a UserControl in any of the tabs? If so, also put a breakpoint in the Loaded event. At least when you hit the breakpoint, the background thread will pause and you might be able to see which object is null.
Another brute force method I use is to comment out entire blocks of code, run and test, and gradually uncomment line by line until it breaks. Then you know at least one of the potential crash locations.

Categories

Resources