C#内存损坏错误

C#内存损坏错误,c#,voip,C#,Voip,我不能发布代码(专有问题),但是有人知道什么类型的东西会导致C#中的以下错误吗。当另一个客户端结束调用时,我编写的VOIP客户端(使用反向路径api)会抛出它。错误是: System.AccessViolationException was unhandled Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt." So

我不能发布代码(专有问题),但是有人知道什么类型的东西会导致C#中的以下错误吗。当另一个客户端结束调用时,我编写的VOIP客户端(使用反向路径api)会抛出它。错误是:

System.AccessViolationException was unhandled
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
  Source="System.Windows.Forms"
  StackTrace:
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 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 System.Windows.Forms.Application.Run(Form mainForm)
       at CollabAnalysisSF.Edge.GUI.Forms.Program.Main() in d:\data\beyerss\Desktop\client\GUI\ARGui\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
更新:

原来我们使用的一个库发送了一个我们不知道的事件,问题就在那里的某个地方。现已修复。

如果调用非托管代码(例如dll),则可能会发生此类问题。当编组出现严重错误时,可能会发生这种情况


您能告诉我们您是否正在调用非托管代码吗?如果是这样,您是在使用默认编组还是更具体的东西?从堆栈跟踪的外观来看,您是否使用了不安全的代码,例如指针等?这可能是您的问题。

列出一些可能性:

  • 对象被处置后正在使用。如果您在终结器中处理托管对象,则经常会发生这种情况(您不应该这样做)
  • 您正在使用的某个对象的一个未经管理的实现存在错误,它损坏了进程内存堆。在DirectX、GDI和其他方面经常发生这种情况
  • 托管-非托管边界上的Mashaling存在缺陷。在代码的非托管部分上使用托管指针之前,请确保将其锁定
  • 您正在使用不安全的块并使用它做有趣的事情

在您的情况下,Windows窗体可能会出现问题。但问题不在于它正在发生,而在于它没有被正确报道;你可能还是做错了什么


您是否能够使用HWND确定导致错误的控件?总是一样吗?在应用程序崩溃之前,这个控件是否正在做一些有趣的事情?控件的未标记部分是自定义窗口还是标准控件?

下面是更详细的堆栈跟踪。在我看来,它似乎与System.Windows.Form.dll有关

目标站点列为
{IntPtr DispatchMessageW(MSG ByRef)}

模块下有System.windows.forms.dll