VB.NET中的System.AccessViolationException
我正试图追踪这个错误,甚至捕获它,以防止它使应用程序崩溃。该应用程序是使用.NET4在VB.NET中编写的VB.NET中的System.AccessViolationException,.net,vb.net,.net,Vb.net,我正试图追踪这个错误,甚至捕获它,以防止它使应用程序崩溃。该应用程序是使用.NET4在VB.NET中编写的 Application: Satcom Discovery Socket.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.AccessViolationException Stack:
Application: Satcom Discovery Socket.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
at System.Net.UnsafeNclNativeMethods+SafeNetHandles.closesocket(IntPtr)
at System.Net.SafeCloseSocket+InnerSafeCloseSocket.ReleaseHandle()
at System.Runtime.InteropServices.SafeHandle.DangerousRelease()
at System.Net.SafeCloseSocket.CloseAsIs()
at System.Net.Sockets.Socket.Dispose(Boolean)
at System.Net.Sockets.Socket.Dispose()
at System.Net.Sockets.Socket.Close(Int32)
at System.Net.Sockets.NetworkStream.Dispose(Boolean)
at System.IO.Stream.Close()
at MySql.Data.MySqlClient.TimedStream.Close()
at MySql.Data.MySqlClient.MySqlStream.Close()
at MySql.Data.MySqlClient.NativeDriver.Close(Boolean)
at MySql.Data.MySqlClient.Driver.Dispose(Boolean)
at MySql.Data.MySqlClient.Driver.Close()
at MySql.Data.MySqlClient.MySqlConnection.CloseFully()
at MySql.Data.MySqlClient.MySqlConnection.Close()
at SatcomDiscoverySocket.modDatabase.DeleteStatus(SatcomDiscoverySocket.Status ByRef, Int32)
at SatcomDiscoverySocket.frmSocket.TimerSocketConn_Tick(System.Object, System.EventArgs)
at System.Windows.Forms.Timer.OnTick(System.EventArgs)
at System.Windows.Forms.Timer+TimerNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
at System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(System.String[])
at SatcomDiscoverySocket.My.MyApplication.Main(System.String[])
事件日志中的另一个错误是
故障应用程序名称:Satcom Discovery Socket.exe,版本:1.0.0.0,时间戳:0x5465cfdd
故障模块名称:ntdll.dll,版本:6.1.7601.18247,时间戳:0x521ea8e7
异常代码:0xc0000005
故障偏移量:0x0002e3be
出错进程id:0x94c
故障应用程序启动时间:0x01d004411406ec37
出现故障的应用程序路径:D:\SocketDaemon\Satcom Discovery Socket.exe
故障模块路径:C:\Windows\SysWOW64\ntdll.dll
报告Id:2cefa3fd-70d4-11e4-8cc0-002219a5cbd1
有什么想法吗
我以为我用下面的代码捕获了未处理的异常
'for regular unhandled stuff
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf MYGeneralExceptionHandler
'for threads behind forms
AddHandler Application.ThreadException, AddressOf MyThreadExceptionHandler
任何指点都将不胜感激
谢谢,
AppDomain.UnhandledException
在发生未处理的异常时被调用,但您不能以任何方式捕获或避免异常。这是一件好事,因为AccessViolationException
表示与非托管代码交互时存在严重问题。您使用的是最新版本的MySql连接器吗?您引用的任何包含非托管代码的程序集都可能会出现问题?@Jeroenmoster我原以为会调用函数MYGeneralExceptionHandler,该函数会通过电子邮件向我发送错误的完整描述,并希望指出原因。我的假设是错误的吗?我没有最新的mySQL连接器,我相信我使用的是6.4.4。你认为这与mySQL有关吗?如果CLR本身发生未经处理的异常,应用程序将立即终止,之后不会运行任何托管代码,包括任何异常处理程序。不幸的是,在这种情况下你无能为力。我不知道MySQL连接器是否是问题所在,但它似乎是(压力似乎是)唯一可能导致问题的第三方代码。其他潜在的原因是CLR本身的错误(罕见但并非闻所未闻,请检查您是否有最新的更新)或在您的应用程序中插入的恶意DLL正在欺骗您。您可以尝试在干净的机器上运行它(除了.NET和您的服务外,没有安装任何软件)。这是一个环境问题,关闭套接字当然不会使您的程序崩溃。这种崩溃的根源是挂起未编写且通常未安装在操作系统上的套接字的cr*ppy代码。反恶意软件,防火墙,使用监控,诸如此类的恶意软件。积极清理你的机器。