简体   繁体   English

Windows 窗体崩溃:在全局异常处理程序中捕获到意外的 NullReferenceException

[英]Windows Forms Crash : Unexpected NullReferenceException caught in Global Exception Handler

We have developed a windows forms application that captures user interactions ie Typed text, clicks.我们开发了一个 windows 窗体应用程序,它捕获用户交互,即键入的文本、点击。 Sometimes, out of the blue on some machine, we get the following exception:有时,在某些机器上突然出现以下异常:

Object reference not set to an instance of an object.

   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at Recorder.Program.GlobalExceptionHandler(Object sender, UnhandledExceptionEventArgs args)
   at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
   at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at Recorder.Program.Main(String[] args)

The issue is not replicated in Development or Testing environment, but occurs in release.该问题不会在开发或测试环境中复制,而是在发布中发生。 Though all our code is covered with exception handling, the above error occurs in the main method and gets caught in the GlobalExcptionHandler.尽管我们所有的代码都包含异常处理,但上述错误发生在 main 方法中并在 GlobalExcptionHandler 中捕获。 The exception has no details nor stack trace.异常没有详细信息也没有堆栈跟踪。

ExceptionMessage - Object reference not set to an instance of an object. 
ExceptionSource -   
ExceptionTarget -   
StackTrace - Logging Stack Trace is disabled

I tried to look up the issue online, found the following links those seems similar, but again with no solutions :我试图在网上查找问题,发现以下链接看起来很相似,但同样没有解决方案:

http://arnosoftwaredev.blogspot.com/2005/07/pragmatic-solutions-for-imperfect.html http://arnosoftwaredev.blogspot.com/2005/07/pragmatic-solutions-for-imperfect.html

http://dotnet.community/threads/somebody-help-me-with-this-error-plz.13965/#post-60920 http://dotnet.community/threads/somebody-help-me-with-this-error-plz.13965/#post-60920

Usually we have noticed, it gets crashed soon after installing the product, or when resource-intensive applications are running ie MS Teams, MS Excel通常我们已经注意到,它在安装产品后很快就会崩溃,或者在运行资源密集型应用程序时崩溃,例如 MS Teams、MS Excel

Please guide!请指导!

I would start by looking at any info or warning messages in the compiler "Error list" tab.我将首先查看编译器“错误列表”选项卡中的任何信息或警告消息。 The Roslyn compiler is generally pretty good at pointing out uninitialised variables. Roslyn 编译器通常非常擅长指出未初始化的变量。 Once you have fixed all those warnings/info, turn on "Warnings as errors" to make sure you don't get any new ones.修复所有这些警告/信息后,打开“警告为错误”以确保您不会收到任何新警告。

Also, look for any conditionally compiled code:另外,查找任何有条件编译的代码:

#if DEBUG
.. something gets initialised  
#endif

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM