即使异常

时间:2017-04-03 11:50:44

标签: visual-studio visual-studio-2013

在库中,我使用Marshal.GetActiveObject获取一个活动应用程序实例的辅助函数。问题是,当我使用visual studio进行调试时,它会中断/抛出以下异常:

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll and wasn't handled before a managed/native boundary

Additional information: Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

enter image description here

如果我没有处理异常,但是在库中,异常会在try ... catch中被捕获。

我启用了“启用我的代码”,但它不会改变任何内容。

所以我查找了“System.Runtime.InteropServices.COMException”但已经禁用了“Thrown”。 “User-unhandled”也是如此。

附加信息:

  • Visual studio 12.0.40629 Update 5
  • ReSharper 2016.3

是否有其他选项要查找或我是否有一个损坏的可视化工作室,我应该重置所有IDE +插件?

谢谢。

编辑:代码

在库A(外部软件的API)中:IApplication

的定义

在图书馆B(我的):

public static bool TryGetRuntime(out IApplication app)
{
    try
    {
        app = Marshal.GetActiveObject("TheApplicationId") as IApplication;
    }
    catch (COMException)
    {
        app = null;
    }
    return app != null;
}

在App C中:

IApplication app;
if (HelperClass.TryGetRuntime(out app)) {
    //do some work
}

0 个答案:

没有答案