【发布时间】:2021-11-19 15:45:55
【问题描述】:
我们开发了一个 Windows 窗体应用程序,它可以捕获用户交互,即键入的文本、点击。有时,在某些机器上,我们会出乎意料地得到以下异常:
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)
该问题不会在开发或测试环境中复制,而是在发布中发生。尽管我们所有的代码都包含了异常处理,但上述错误发生在 main 方法中并被 GlobalExcptionHandler 捕获。该异常没有详细信息,也没有堆栈跟踪。
ExceptionMessage - Object reference not set to an instance of an object.
ExceptionSource -
ExceptionTarget -
StackTrace - Logging Stack Trace is disabled
我尝试在网上查找问题,发现以下链接看起来相似,但同样没有解决方案:
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
通常我们已经注意到,它在安装产品后不久就会崩溃,或者在运行资源密集型应用程序(例如 MS Teams、MS Excel)时崩溃
请指导!
【问题讨论】: