在C#库中处理COM库崩溃 [英] Handle COM library Crash inside C# library

查看:178
本文介绍了在C#库中处理COM库崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在我的.NET库中调用C库方法,如下所示。

I am calling a C library method in my .NET library as below .

[DllImport(@"abc.dll",CallingConvention=CallingConvention.Cdecl)]
private static extern unsafe int DoSomething(



使用  DoSomething()


这两个都被加载到w3wp,因为它们是w3wp的一部分web项目。由于C库里面有一些例外,整个wo rker进程正在崩溃。

Both of these gets loaded into to w3wp since they are part of the web project. Due to some exception inside C library, whole worker process is getting crashed.


无论如何在我调用COM方法的C#类中处理这个问题?

Is there anyway to handle this inside the C# class where I call COM method?

推荐答案

你能更具体地说明"某些异常"是什么吗?它遇到异常还是抛出异常?DLL实际上是一个C ++程序,它将函数公开为C函数吗?这是非常常见的。

Can you be more specific about what the "some exception" is? Does it encounter an exception or does it throw an exception? Is the DLL actually a C++ program that exposes the function as a C function? That is extremely common.

请参阅
Visual C ++中的异常处理
及其中的小节。

See Exception Handling in Visual C++ and the subsections in there.

参见
托管C ++ Wrapper for Unmanaged Code。
这是一种可能性;你可以编写一个C ++类库来调用C DLL并在C ++中处理异常。

See Managed C++ Wrapper For Unmanaged Code. That is one possibility; you could write a C++ Class Library that calls the C DLL and handle the exception in C++.


这篇关于在C#库中处理COM库崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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