确定 AccessViolationException DragDrop.DoDragDrop 的原因

发布于 2024-11-15 19:45:53 字数 3119 浏览 3 评论 0原文

我的 WPF 应用程序在某些计算机上崩溃,并在开始拖动操作时出现 AccessViolationException。

困难在于它只发生在我们的构建服务器的构建上,并且当我在 Visual Studio 2010 中本地构建时永远不会崩溃。所以我无法单步执行代码。

我有以下信息:

  • 我们正在使用 .net 4.0
  • 仅当应用程序作为 64 位进程运行时才会崩溃,32 位就可以了。
  • 仅从构建服务器进行构建时会崩溃。
  • 不会在每台计算机上崩溃,只是在我们这里拥有的一小部分笔记本电脑上崩溃。顺便说一下,这些都是相同的型号 和硬件配置。都有 Windows 7,有些有 sp1,有些 不。

下一步我应该采取什么措施来诊断这个问题?

这是崩溃的堆栈跟踪,它似乎发生在非托管代码中:

at MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
at System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
at System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects)
at Acquire.Common.UI.Behaviours.DragDropBehaviour.StartDrag(RoutedEventArgs e)
at Acquire.Common.UI.Behaviours.DragDropBehaviour.AttachedElementMouseMove(Object sender, MouseEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at Acquire.Mica.Application.App.Main()

更新: 通过反复试验,我能够确定导致这次崩溃的确切代码行,并且它似乎完全有效。作为实验,我禁用了包含有问题的代码行的方法的代码优化,并且应用程序不再崩溃。

I have a WPF application that is crashing on some computers with an AccessViolationException when a drag operation is started.

The difficulty is it is only occurring on builds from our build server, and never crashes when I build locally in Visual Studio 2010. So I cannot step through the code.

I have the following information:

  • We're using .net 4.0
  • Only crashes when the application is run as a 64bit process, 32bit is fine.
  • Only crashes for builds from the build server.
  • Doesn't crash on every computer, just on a small subset of laptops we have here. Which incidentally are all the same model
    and hardware configuration. All have
    Windows 7, and some have sp1, some
    don't.

What is the next step I should take to diagnose this issue?

Here's the stack trace from the crash, it seems to be occurring in unmanaged code:

at MS.Win32.UnsafeNativeMethods.DoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
at System.Windows.OleServicesContext.OleDoDragDrop(IDataObject dataObject, IOleDropSource dropSource, Int32 allowedEffects, Int32[] finalEffect)
at System.Windows.DragDrop.OleDoDragDrop(DependencyObject dragSource, DataObject dataObject, DragDropEffects allowedEffects)
at Acquire.Common.UI.Behaviours.DragDropBehaviour.StartDrag(RoutedEventArgs e)
at Acquire.Common.UI.Behaviours.DragDropBehaviour.AttachedElementMouseMove(Object sender, MouseEventArgs e)
at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
at Acquire.Mica.Application.App.Main()

Update:
Through trial and error I was able to determine the exact line of code that was causing this crash, and it appears to be perfectly valid. As an experiment I disabled code optimization for the method containing the offending line of code, and the application no longer crashes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

煮酒 2024-11-22 19:45:53

AV 异常是最糟糕的,您应该意识到问题可能源自系统中完全不同的部分。

通常发生的情况是,您不小心访问了您无权访问的内存位置,程序继续照常执行,但是稍后另一种方法尝试访问该内存位置,并通过读取不正确的数据位置而导致错误错误。

要进行调试,我建议您利用 gflags,微软提供的一个用于检测深度损坏的工具。我使用了它几次,它节省了我数小时甚至数天的调试工作。

AV exception are the worst, you should be aware that the problem may originate from completely different part in the system.

What normally happens is that you accidently access a memory location that you don't have access to, the program continues to execute as usual, however later on another method tries to access that memory location and causes an error by reading incorrect data place there by mistake.

To debug I suggest that you take advantage of gflags, a tool offered by Microsoft to detect deap corruptions. I used it several times and it saved me hours if not days of debugging effort.

随波逐流 2024-11-22 19:45:53

只是预感,但既然您表示正在优化代码并使用混合 32/64 位环境:

  1. 请验证构建服务器是否为 x64 位环境。
  2. 验证客户端具有正确版本的.Net 环境。
  3. 验证正在运行该应用程序的客户端正在运行正确的版本,即。 64 位仅由 win7 x64 系统运行,反之亦然。
  4. 确保清除服务器临时目录,临时目录中的先前构建可能会导致诸如此类的奇怪问题。

另请注意,微软开发人员隔离两个环境的方式是愚蠢的,并且注册表项/程序文件等未存储在程序指示的位置。这是我在公司创建的一些应用程序中必须克服的主要障碍。

我也相信剪贴板和拖放调用是 STA(单线程设备)调用。崩溃可能是由于 STA 与 MTA 之间的冲突造成的。您是否有用 [STAThread] 修饰的 Main() 函数?

我个人发现这篇关于 64 位迁移的文章很有用:http://www.codeguru.com/cpp/misc/samples/basicprogramming/article.php/c16093/Seven-Steps-of-Migration-a-Program-to-a-64bit-System。嗯

Just a hunch, but since you indicated you are optimizing code, and using a mixed 32/64 bit environment:

  1. Verify the build server a x64 bit environment.
  2. Verify the clients have the proper version .Net environment.
  3. Verify the clients that are running the app are running the right version, ie. 64 bit is only being run by win7 x64 systems and vice versa.
  4. Make sure you clear out the servers temp directories, previous builds in temp directories can cause odd issues such as this.

Also note, the Microsoft developers are idiotic in they way they segregated the two environments, and registry keys / program files etc. are not stored where the program indicates. This was a major stumbling block I had to get past with some apps we created at my company.

Also I belive clipboard & drag+drop calls are STA(Single threaded apratments) calls. The crash could be from a conflict between STA to MTA. Do you have the Main() function decorated with the [STAThread] ?

I personally found this article on 64 bit migration useful: http://www.codeguru.com/cpp/misc/samples/basicprogramming/article.php/c16093/Seven-Steps-of-Migrating-a-Program-to-a-64bit-System.htm

水波映月 2024-11-22 19:45:53

首先检查机器上是否安装了所有更新。

稍后您可以使用 debugdiag 创建故障转储并检查第一次机会和第二次机会异常以获取有关此事的更多信息。

问候,

伊恩

First of all check if all updates are installed on the machines.

Later you could use debugdiag to create a crashdump and check the firstchance and secondchance exceptions to get more info on the matter.

Greetings,

Ian

像你 2024-11-22 19:45:53

我要做的第一件事是更新这些笔记本电脑的显卡驱动程序。

在 MS.Win32.UnsafeNativeMethods..

这通常意味着 MS .NET 工程师试图告诉您:
“嘿,我们没有写这个,它就崩溃了。”

1st thing I would do is to update the video card driver of those laptops.

at MS.Win32.UnsafeNativeMethods..

This usually means that MS .NET engineer trying to tell you:
"Hey, we didn't write this and it crashed."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文