来自非托管代码的 System.AccessViolationException? [英] System.AccessViolationException from unmanaged code?

查看:39
本文介绍了来自非托管代码的 System.AccessViolationException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写这个库,它通过将由托管代码使用的媒体基础框架在 C++/CLI 中实现一些基本的音频播放器功能.我可以很好地播放音频、停止、暂停等.对于不熟悉 Media Foundation 的任何人,媒体会话会发布您可以处理的通知事件.这是通过使用 IMFAsyncCallback 对象在会话对象上调用 BeginGetEvent 来完成的.IMFAsyncCallback 定义了您应该实现以处理事件的方法 Invoke(IMFAsyncResult).发生事件时,工作线程上的会话对象将调用 invoke 方法,并使用您可以查询事件信息的 IMFAsyncResult 对象.这个结果对象由事件线程创建和拥有.

I'm writing this library that implements some basic audio player features in C++/CLI via the Media Foundation framework that will be consumed by managed code. I can play audio, stop, pause, etc just fine. For anyone who is not familiar with Media Foundation, the media session posts events that you can handle for notifications. This is done by calling BeginGetEvent on the session object with an IMFAsyncCallback object. The IMFAsyncCallback defines the method Invoke(IMFAsyncResult) that you should implement to handle the events. When an event occurs, the invoke method is called by the session object on a work thread with an IMFAsyncResult object that you can query for the event info. This result object is created and owned by the event thread.

在我的 Invoke 实现中,每当我尝试使用传递的 IMFAsyncResult 对象执行任何操作(包括仅调用 QueryInterface 或其他操作)时,我都会收到 System.AccessViolationException.我实现了IMFAsyncCallback 的对象是在CRT 堆上分配的基本C++ 类(非托管),并且事件发布在会话对象拥有的线程上,该线程也分配在CRT 堆上.

In my implementation of Invoke, whenever I try and do anything (that includes just calling QueryInterface or something) with the IMFAsyncResult object that I am passed, I get a System.AccessViolationException. The object I have implementing IMFAsyncCallback is a basic C++ class (not managed) allocated on the CRT heap and the events are posted on a thread owned by the session object also allocated on the CRT heap.

  1. 可能导致此异常的原因是什么?

  1. What could be causing this exception?

为什么我会从用普通旧 C++ 实现的代码中抛出 .NET 托管异常?当您使用混合模式程序集时会发生这种情况吗?

Why am I getting a .NET managed exception thrown from code that is implemented in plain old C++? Is that just what happens when you have a mixed mode assembly?

推荐答案

捕获崩溃转储,然后将其加载到 VS 2010 或 WinDbg 中进行分析,一切都将被揭示.VS 2010 会更容易,但 WinDbg 可能更有效.

Capture a crash dump, then load it into VS 2010 or WinDbg for analysis, and all shall be revealed. VS 2010 will be easier, but WinDbg might be more effective.

由于使用 WinDbg 是更复杂的选项,我将详细说明(根据您的目标平台选择以下的 32 位或 64 位版本):

Since using WinDbg is the more complicated option I'll elaborate on that (choose the 32-bit or 64-bit versions of the following according to your target platform):

  • Download and install Debugging Tools for Windows
  • Configure debugging symbols for the Microsoft Symbol Server

.sympath srv**http://msdl.microsoft.com/download/symbols

  • 将故障转储文件加载到 WinDbg(文件->打开故障转储...)
  • 为您的模块配置调试符号

.sympath+

  • SOS 扩展加载到 WinDbg
  • Load SOS extensions into WinDbg

.loadby sos mscorwks;* fw 2-3.5

.loadby sos clr;* fw 4

  • 下载、提取和加载 SOSEX 扩展到 WinDbg
  • Download, extract and load SOSEX extensions into WinDbg

.load sosex

  • 让 WinDbg 来分析

!analyze -v

  • 使用 SOSEX 显示当前线程堆栈(包括托管和非托管帧)

!mk

这很可能会回答您的问题.

This will most likely answer your questions.

这篇关于来自非托管代码的 System.AccessViolationException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆