【问题标题】:C# Corrupt Memory ErrorC# 损坏内存错误
【发布时间】:2010-09-06 06:52:18
【问题描述】:

我无法发布代码(专有问题),但有人知道什么类型的东西会导致 C# 中出现以下错误。当另一个客户端结束呼叫时,我编写的VOIP客户端(使用counterpath 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: 

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

【问题讨论】:

    标签: c# voip


    【解决方案1】:

    一些可能性的列表:

    • 对象在被释放后被使用。如果您在终结器中处理托管对象,这可能会发生很多情况(您不应该这样做)。
    • 您正在使用的对象之一的无人管理实现存在错误,它破坏了进程内存堆。经常使用 DirectX、GDI 等。
    • 托管-非托管边界上的混搭存在缺陷。确保在将托管指针用于代码的非托管部分之前将其固定。
    • 您正在使用不安全的块并用它做一些有趣的事情。

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

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

    【讨论】:

      【解决方案2】:

      如果您正在调用非托管代码,例如一个dll。当编组出现严重错误时,可能会发生这种情况。

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

      【讨论】:

        【解决方案3】:

        这是更详细的堆栈跟踪。在我看来它与 System.Windows.Form.dll 有关

        TargetSite 被列为{IntPtr DispatchMessageW(MSG ByRef)}
        在模块下它有 System.windows.forms.dll

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-11
          • 2017-01-28
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多