从非托管code System.AccessViolationException? [英] System.AccessViolationException from unmanaged code?

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

问题描述

我在写这个库,实现了一些基本的音频播放功能,在C ++ / CLI通过,将由管理code被消耗的媒体基础架构。我可以播放音频,停止,暂停,等就好了。对于任何人谁不熟悉媒体基金会,媒体会话帖子事件,您可以处理通知。这是通过与IMFAsyncCallback对象的会话对象上调用BeginGetEvent完成。该IMFAsyncCallback定义方法调用(IMFAsyncResult),你应该实现处理事件。当一个事件发生时,调用方法由上,你可以为事件信息查询的IMFAsyncResult对象的工作线程会话对象。这个结果对象被创建并拥有的事件线程。

在我的实现调用,每当我尝试做任何事情(只包括调用的QueryInterface或某物),我通过了IMFAsyncResult对象,我得到一个System.AccessViolationException。我已经实现IMFAsyncCallback的对象是一个基本的C ++类(非托管)分配在CRT堆和事件张贴在也分配在CRT堆会话对象拥有的线程。

  1. 什么引起这个异常?

  2. 为什么我会收到来自code抛出一个.NET托管异常是在普通的老式C ++实现的?那是当你有一个混合模式组件刚刚发生了什么?

解决方案

<一个href="http://www.wintellect.com/CS/blogs/jrobbins/archive/2010/06/17/how-to-capture-a-minidump-let-me-count-the-ways.aspx"相对=nofollow>捕捉崩溃转储,然后将其加载到VS 2010或WinDbg中进行分析,所有的必然显现。 VS 2010年将是更容易,但WinDbg中可能会更有效。

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

  • 下载并安装 Windows调试工具
  • 配置调试符号为 Microsoft符号服务器

    .sympath SRV *&LT; SymbolCacheDir&GT; * HTTP://msdl.microsoft.com/download/symbols

  • 加载故障转储文件到WinDbg中(文件 - >打开崩溃转储...)

  • 配置调试符号在你的模块

    .sympath +&LT; PrivatePdbDir&GT;

  • 加载 SOS 扩展到WinDbg的

    .loadby索斯mscorwks; * FW 2-3.5

    .loadby SOS CLR; * FW 4

  • 下载,提取和加载 SOSEX 扩展到WinDbg的

    .load&LT; Sosex32or64Dir&GT; \ sosex

  • 让WinDbg中做了分析

    !分析-v

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

    !MK

这很可能会回答你的问题。

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.

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. What could be causing this exception?

  2. 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?

解决方案

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.

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*<SymbolCacheDir>*http://msdl.microsoft.com/download/symbols

  • Load the crash dump file into WinDbg (File->Open Crash Dump...)

  • Configure debugging symbols for your modules

    .sympath+ <PrivatePdbDir>

  • Load SOS extensions into WinDbg

    .loadby sos mscorwks; * fw 2-3.5

    or

    .loadby sos clr; * fw 4

  • Download, extract and load SOSEX extensions into WinDbg

    .load <Sosex32or64Dir>\sosex

  • Let WinDbg do the analysis

    !analyze -v

  • Use SOSEX to show the current thread stack (including both managed and unmanaged frames)

    !mk

This will most likely answer your questions.

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

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