【问题标题】:AccessViolationException on ToolTip that faults COMCTL32.dll - .NET 4.0工具提示上的 AccessViolationException 导致 COMCTL32.dll 出错 - .NET 4.0
【发布时间】:2012-01-10 06:45:21
【问题描述】:

我们的 Windows 窗体应用程序存在问题,由于堆栈跟踪表明发生在 ToolTip 控件中的 AccessViolationException 类型的未处理异常而终止。

错误发生在应用程序的不同时间,我们目前无法可靠地重现它。 在这个阶段,它只发生在 Windows 7 的生产环境中,并且只针对某些用户,而不是其他用户——即使在以类似方式使用该应用程序的用户中也是如此。 它似乎与机器相关,因此我们已经完成了诸如确保图形驱动程序是最新的操作。

在事件日志中,总是记录 2 个不同的错误,一个与我们的应用程序有关:

Application: <Application>.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
   at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ToolTip.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ToolTip+ToolTipNativeWindow.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 <Company>.Windows.Forms.<Application>.Startup.Main(System.String[])

还有一个与 comctl32.dll 相关的:

Faulting application name: <Application>.exe, version: 7.13.0.2086, time stamp: 0x4ec5e710
Faulting module name: comctl32.dll, version: 5.82.7601.17514, time stamp: 0x4ce7b82c
Exception code: 0xc0000005
Fault offset: 0x00043286
Faulting process id: 0xcdc
Faulting application start time: 0x01cca96312446309
Faulting application path: C:\Program Files\<Company>\Client\<Application>.exe
Faulting module path: C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_ec83dffa859149af\comctl32.dll
Report Id: b425143c-1575-11e1-bccf-6c626d955bf1

第一个堆栈跟踪会根据工作流中错误发生的位置而变化,但是堆栈上的前 9 个项目始终相同,不同之处通常是出现在 Main() 方法和RunMessageLoop 方法。例如:

Application: <Application>.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
Stack:
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
   at System.Windows.Forms.NativeWindow.DefWndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ToolTip.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ToolTip+ToolTipNativeWindow.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.RunDialog(System.Windows.Forms.Form)
   at System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window)
   at System.Windows.Forms.Form.ShowDialog()
   at <Company>.Windows.Forms.<Application>.ApplicationForm.<EventSubscribingMethod>(System.Object, System.EventArgs)
   at <Company>.<Application>.<Class1>.RaiseShowResultDialogNowEvent()
   at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry)
   at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(System.Object)
   at System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry)
   at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
   at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.ScrollableControl.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Form.WndProc(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
   at System.Windows.Forms.Control+ControlNativeWindow.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 <Company>.Windows.Forms.<Application>.Portal.Startup.Main(System.String[])

---- 更新----

我收到了包含 Main 中的一些代码的请求,我不想包含所有代码,但摘录如下:

 <System.STAThread()> _
    Public Shared Function Main(ByVal args() As String) As Integer
        -- Perform startup validation, setup logging framework, etc
        ...
        Dim appLife as new ApplicationContext(myStartupForm)
        Application.Run(appLife)
        Return 0

    End Function

一些补充说明:

有人知道是什么原因造成的吗?

谢谢,

【问题讨论】:

  • 请在Main() 中显示代码。看起来你没有打电话给Application.Run
  • 感谢您提供额外信息。 0xc0000005 是本机 NullReferenceException。正如你所说,你正在覆盖 WndProc 我可能会在那里寻找任何空指针。

标签: winforms windows-7 .net-4.0 tooltip


【解决方案1】:

根据 MS 的说法,DataGrid 控件在某些情况下存在一个已知问题,避免此问题的方法是禁用 DataGrid 控件的工具提示。

我们将在接下来的几天内实施更改并将其推广到一个试点小组,我将在大约一周后回复成功/失败(当然,除非在那之前发生失败)。

根据MS要设置的属性是DataGridView.ShowCellToolTips = false;

这解决了我们的应用程序的问题。

要重现该问题,我们需要执行以下操作:

  • 将鼠标悬停在 DataGridView 中我们知道会显示工具提示的单元格上
  • 在显示工具提示之前将 Alt 选项卡转到另一个应用程序(将显示在您的应用程序顶部)
  • 不要移动鼠标
  • Alt 选项卡返回我们的应用程序
  • 我们的应用程序崩溃了。

【讨论】:

  • 哇!感谢您的回答,我终于能够复制我的问题stackoverflow.com/q/7458915/68936!不得不为所有datagridview禁用工具提示很糟糕,但比我想的访问冲突要好。您是否碰巧有任何参考 URL,或者“根据 MS”是否意味着您通过与他们的私人对话获得了信息?再次感谢您发布您的答案。
  • 嗨,吉米,我通过付费支持得到了答案。不幸的是,他们没有可以指出我的官方知识库。不过,我很高兴这对您有所帮助 :-)
  • 我欠你一顿午餐.. 非常感谢这个很棒的答案。我花了 2 周的时间才发现这仍然没有出现,但今天由于您的礼貌.. 我可以找到这一切。你是怎么知道的?
  • github上的相关问题github.com/Microsoft/dotnet/issues/402
  • 我在这里找到了有关工具提示问题的更多信息:support.microsoft.com/en-us/help/2892345/…。如果您想在数据网格上使用工具提示,请包括一个替代方案。
【解决方案2】:

似乎在Form.Deactivate 上设置DataGridView.ShowCellToolTips = false 可以防止崩溃。可以在 Form.Activate 上重置为 true。

然而,工具提示仍然显示在新聚焦的窗口上方 - 但我想这比崩溃要好。

甚至更好:

该问题仅在未启用视觉样式时出现。

在实例化任何表单之前在main() 中添加Application.EnableVisualStyles() 可以解决问题。

【讨论】:

  • 确认设置 Application.EnableVisualStyles() 可以解决问题
【解决方案3】:

更多细节 https://github.com/Microsoft/dotnet/issues/402

6年后,不幸的是,解决方案仍然是“使用comctl v6”

【讨论】:

  • 2021 到这里还没有解决,这是一个无法解决的问题:(
猜你喜欢
  • 1970-01-01
  • 2012-08-14
  • 2016-11-03
  • 2015-11-03
  • 1970-01-01
  • 1970-01-01
  • 2015-03-02
  • 2021-01-13
  • 2011-02-18
相关资源
最近更新 更多