gpt4 book ai didi

.net - 如何调试 "Safe handle has been closed"错误

转载 作者:行者123 更新时间:2023-12-04 02:13:52 24 4
gpt4 key购买 nike

我继承的代码不断崩溃,并出现以下错误(根本没有改变):

System.ObjectDisposedException: Safe handle has been closed
at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(
SafeFileHandle hFile, NativeOverlapped* lpOverlapped,
Int32& lpNumberOfBytesTransferred, Boolean bWait)
at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
at System.Threading.ThreadHelper.ThreadStart_Context(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.Threading.ThreadHelper.ThreadStart()

这只是因为以前的开发人员添加了 AppDomain.UnhandledException Event 才被发现。 .

如果我删除它,应用程序就会崩溃,并显示 Dr Watson 消息(发送反馈等),而不是通常的 .NET 对话框(带有继续选项和堆栈跟踪)。

我查过,与 Thread.Abort无关

我如何尝试从堆栈跟踪中找到这个问题的原因,而不是在应用程序的代码中?

最佳答案

从 System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent() 和 Microsoft.Win32.UnsafeNativeMethods 被引用的事实来看,我会认为您有一个 COM 组件,该组件具有访问端口的内部线程,例如用于串行或 TCP/IP 数据。

看起来线程在启动序列期间抛出异常。可能它正在尝试访问不可用或不存在的端口。这会失败,并且异常不会被处理,因此会通过代码传播回来。

尝试从 UnhandledException 事件记录更多信息,以了解这可能从哪里开始。

关于.net - 如何调试 "Safe handle has been closed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1625081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com