I am working on an application where we can open child modules using multiple tab display. But when someone switches between the tabs so frequently or clicks on a tab more than once then sometimes I got fatal nullreference exception which further crash my whole application. I have applied complete exception handling but this exception is not getting caught anywhere. I think this might be some windows related exceptions which are happening on the kernel. I am posting the call stack also and to get the info on the exception I used profiling tool.
System.NullReferenceException occurred Message: Exception thrown: 'System.NullReferenceException' in System.Windows.Forms.dll Additional information: Object reference not set to an instance of an object.
This call stack is above of the below call stack - this I got from the profiling tool.
>class="System.Windows.Forms.UnsafeNativeMethods" method="WaitMessage()"
class="System.Windows.Forms.Application+ComponentManager" method="System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr,int,int)"
class="System.Windows.Forms.Application+ThreadContext" method="RunMessageLoopInner(int,System.Windows.Forms.ApplicationContext)"
class="System.Windows.Forms.Application+ThreadContext" method="RunMessageLoop(int,System.Windows.Forms.ApplicationContext)"
class="System.Windows.Forms.Application" method="RunDialog(System.Windows.Forms.Form)"
class="System.Windows.Forms.Form" method="ShowDialog(System.Windows.Forms.IWin32Window)"
class="System.Windows.Forms.Form" method="ShowDialog()"
class="OuterNamespace.Portal.Utilities.Forms.MessageBoxEx" method="Show(System.String,System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)"
class="OuterNamespace.Portal.Utilities.Forms.MessageBoxEx" method="Show(System.String,System.Windows.Forms.MessageBoxButtons,System.Windows.Forms.MessageBoxIcon)"
class="OuterNamespace.Portal.Components.ExceptionHandler" method="Handle(System.Exception,System.String,OuterNamespace.Portal.Constants.Logging.LogType)"
class="OuterNamespace.Portal.Components.ExceptionHandler" method="HandleException(System.Exception,boolean,OuterNamespace.Interfaces.RuntimeInformation.IRuntimeInformationManager)"
class="OuterNamespace.Exception.Manager.ExceptionManager" method="CallUnhandledExceptionHandler(System.Exception)"
class="OuterNamespace.Exception.Manager.ExceptionManager" method="HandleUnhandledException(System.Exception)"
class="OuterNamespace.Application.ApplicationContext" method="Application_ThreadException(System.Object,System.Threading.ThreadExceptionEventArgs)"
class="System.Windows.Forms.Application+ThreadContext" method="OnThreadException(System.Exception)"
class="System.Windows.Forms.Control" method="WndProcException(System.Exception)"
class="System.Windows.Forms.Control+ControlNativeWindow" method="OnThreadException(System.Exception)"
class="System.Windows.Forms.NativeWindow" method="Callback(System.IntPtr,int,System.IntPtr,System.IntPtr)"
class="System.Windows.Forms.UnsafeNativeMethods" method="SetFocus(System.Runtime.InteropServices.HandleRef)"
------------------------------------------------------------------------
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.FocusActiveControlInternal() Unknown
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WmSetFocus(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.UserControl.WmSetFocus(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.UserControl.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.FocusActiveControlInternal() Unknown
System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.WmSetFocus(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) Unknown
Module.dll!MyNamespace.Wrappers.WindowWrapper.WndProc(ref System.Windows.Forms.Message m) Unknown
System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
Module.dll!MyNamespace.FocusController.FixMouseDoubleClickError.AnonymousMethod__68_0() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry tme) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control caller, System.Delegate method, object[] args, bool synchronous) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate method, object[] args) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate method) Unknown
Module.dll!MyNamespace.FocusController.FixMouseDoubleClickError() Unknown
Module.dll!MyNamespace.FocusController.UpdateAsyncIff.AnonymousMethod__91_0() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Delegate.DynamicInvokeImpl(object[] args) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackDo(System.Windows.Forms.Control.ThreadMethodEntry tme) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(object obj) Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallback(System.Windows.Forms.Control.ThreadMethodEntry tme) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.InvokeMarshaledCallbacks() Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control caller, System.Delegate method, object[] args, bool synchronous) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate method, object[] args) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Control.Invoke(System.Delegate method) Unknown
Module.dll!MyNamespace.FocusController.FixMouseDoubleClickError() Unknown
Module.dll!MyNamespace.FocusController.HandleCpmModalForegroundWindow(System.IntPtr appForegroundWinHdl) Unknown
Module.dll!MyNamespace.FocusController.HandleForegroundWindowChange(System.IntPtr foregroundDetectedHdl) Unknown
Module.dll!MyNamespace.FocusController.ForegroundWindowChangeDetectorOnForegroundWindowChanged(object sender, MyNamespace.Detectors.ForegroundEventArgs foregroundEventArgs) Unknown
Module.dll!MyNamespace.Detectors.ForegroundWindowChangeDetector.OnForegroundWindowChanged(MyNamespace.Detectors.ForegroundEventArgs e) Unknown
Module.dll!MyNamespace.Detectors.ForegroundWindowChangeDetector.ForegroundCallback(System.IntPtr eventHook, uint eventType, System.IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) Unknown
[Native to Managed Transition]
[Managed to Native Transition]
System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason, int pvLoopData) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason, System.Windows.Forms.ApplicationContext context) Unknown
System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) Unknown
Portal.Desktop.exe!OuterNamespace.Portal.Desktop.Program.Main() Unknown
What I have tried:
I am not able to reach to the problem yet so not able to find the workaround or any fix for this.