2008-08-20 164 views
2

我不能发布代码(专有问题),但没有人知道什么类型的东西会导致C#中的以下错误。当由另一个客户端结束呼叫时,我正在写一个VOIP客户端(使用counterpath API)。错误是:C#损坏内存错误

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:

更新:原来我们用的是送别,我们不知道有关事件的图书馆之一,而这一问题在那里的某个地方。现在修复。

回答

3

的一些可能性列表:

  • 一个目的已经设置之后被使用。如果您在终结器中处理托管对象,这可能会发生很多(您不应这样做)。
  • 您正在使用的对象之一的非受控实现被窃听,并且它损坏了进程内存堆。与DirectX,GDI和其他人发生了很多事情。
  • 在托管非托管边界上进行捕获是有缺陷的。在代码的非托管部分使用它之前,请确保您固定了托管指针。
  • 您正在使用不安全的块,并使用它做有趣的事情。

在你区分它可能是与Windows窗体的一个问题。但问题不在于它正在发生,而在于它没有正确报告。你可能仍然做错了什么。

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

1

如果您调用非托管代码,则可能会发生此类问题。一个dll。当编组发生严重错误时可能发生。

你能告诉我们你是否在调用非托管代码?如果是的话,你使用默认的编组或更具体的东西?从堆栈跟踪的外观你是否使用不安全的代码,例如指针和类似的东西?这可能是你的问题。

0

这是一个更详细的堆栈跟踪。它看起来对我来说,它有事情做与System.Windows.Form.dll

的TargetSite被列为{IntPtr DispatchMessageW(MSG ByRef)}
和下模块具有System.Windows.Forms.dll的