嵌入式 firefox/xulrunner 导致 AccessViolationException

发布于 2024-07-26 05:43:06 字数 466 浏览 2 评论 0原文

我已经在很大程度上成功地将 firefox/xulrunner 嵌入到我们的 C# 应用程序中,但这并非没有麻烦。 有时会抛出 AccessViolationException,我认为这是由于 GC 在内存中移动托管对象而导致非托管 xpcom 在移动后尝试使用它。 例如,我为自定义协议创建了一个协议处理程序,该协议实现了 firefox/xulrunner 调用的一些接口。 这样做之后,AccessViolationException 变得更加占主导地位。 我研究了 GCHandle.Alloc(object, GCHandleType.Pinned) 作为可能的解决方案,但找不到有关如何编写自定义编组器以使实现接口“blittable”的类的足够信息。 那么,有人对如何处理这个问题或如何将我的类转换为“blittable”类有任何想法吗? 此外,几乎不可能追踪互操作的哪些部分导致了 AccessViolationException。 呃:-(

感谢您的见解!

I have for the most part successfully embedded firefox/xulrunner into our c# application, but it is not without troubles. Once in a great while a AccessViolationException will be thrown which I believe is caused by the GC moving a managed object in memory and the unmanaged xpcom attempts to use it after it has been moved. For example I created a protocol handler for a custom protocol that implements some interfaces that firefox/xulrunner calls upon. After doing that, the AccessViolationException's became much more predominate. I looked into GCHandle.Alloc(object, GCHandleType.Pinned) as a possible solution, but couldn't find enough information on how to write a custom marshaller to make my class that implemented the interfaces "blittable". So does anyone have any ideas on how to deal with this problem or how to translate my class into a "blittable" one? Also its near impossible to track down what parts of the interop are causing the AccessViolationException. Ugh :-(

Thanks for any insight!

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

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

发布评论

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

评论(1

饮惑 2024-08-02 05:43:06

我相信我通过我问的另一个问题得到了答案 "GetComInterfaceForObject 是否固定对象?”。 基本上我认为 AccessViolationExceptions 是由超出 .net 端范围的对象生成的,如果我的理解是正确的,非托管引用将不会使托管对象保持活动状态。 因此,我创建的任何需要长时间存在以便非托管代码可以调用它的托管对象现在都存储在字段或列表中。 同样在“blittable”对象方面,我还没有找到固定类的方法,但我确实设法弄清楚如何固定实现接口的结构。 该接口是一个互操作接口,定义了 MarshalAs 属性,允许转换为非托管代码,因此显然允许固定对象。 不确定这是否可以通过类实现实现,因为即使它是以与结构完全相同的方式实现的,我仍然收到错误。

:-)

I believe I have an answer to this through the means of another question I asked "does GetComInterfaceForObject pin the object?". Basically what I believe is the AccessViolationExceptions where being generated by an object going out of scope in the .net side, if my understanding is correct the unmanaged reference will not keep a managed object alive. So any managed object that I create that needs to be around for an extended period of time so the unmanaged code can call upon it, is now stored in either a field or a list. Also on the side of a "blittable" object, I haven't found a way to pin a class, but I did manage to figure out how to pin a struct that implemented an interface. The interface was an interop interface that had MarshalAs attributes defined, which allowed the conversion to unmanaged code, therefore apparently allowing the object to be pinned. Not sure if this is possible with a class implementation as I still received errors even though it was implemented in the same exact manner as the struct.

:-)

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