我有一个非常奇怪的问题让我完全难过。我有这样的单元测试:
[TestMethod]
public void InitCaptureCard()
{
// This calls the constructor of a c++ class through
// a c facade. All c++ unit tests pass.
// the DLL containing this class is in the unit test directory
// and all of its dependencies are dynamically loaded
// the unit test, interop and native library are built for x86
var card = new CaptureCardInterop.CaptureCard();
// deletes the object
card.Dispose();
}
如果我在此测试中选择“运行”,它将按预期通过。但是,如果我选择调试,则测试无法启动。相反,如果我打开本机异常处理,我会得到一个EEFileNotFoundException
,如果不这样做,我只会崩溃视觉工作室。死测试运行程序的堆栈跟踪看起来像
clr.dll!Debugger::FirstChanceSuspendHijackWorker(struct _CONTEXT *,struct _EXCEPTION_RECORD *) Unknown
clr.dll!CLRVectoredExceptionHandlerShim(struct _EXCEPTION_POINTERS *) Unknown
ntdll.dll!RtlpCallVectoredHandlers() Unknown
ntdll.dll!RtlDispatchException() Unknown
ntdll.dll!_KiUserExceptionDispatcher@8() Unknown
clr.dll!_SignalHijackStartedFlare@0() Unknown
clr.dll!Debugger::FirstChanceSuspendHijackWorker(struct _CONTEXT *,struct _EXCEPTION_RECORD *) Unknown
clr.dll!CLRVectoredExceptionHandlerShim(struct _EXCEPTION_POINTERS *) Unknown
ntdll.dll!RtlpCallVectoredHandlers() Unknown
ntdll.dll!RtlDispatchException() Unknown
ntdll.dll!_KiUserExceptionDispatcher@8() Unknown
clr.dll!_SignalHijackStartedFlare@0() Unknown
clr.dll!Debugger::FirstChanceSuspendHijackWorker(struct _CONTEXT *,struct _EXCEPTION_RECORD *) Unknown
继续直到它“触发断点”(即在堆栈溢出之前)。
我很难过,因为通常 EEFileNotFoundException
意味着它无法加载本机DLL或其中一个依赖项,但如果是这种情况,我会期望类似的行为,无论是否附加了一个调试器。
更新:尝试了一堆东西之后。在未与我们的构建系统集成的新解决方案中将所有内容复制到新项目会导致一切按预期工作。所以至少我知道问题的位置或多或少。
更新2 :启用本机调试是触发崩溃的原因。