2008-08-20 167 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的