VC++ (MFC 사용)와 C++/CLI 클래스가 모두 포함 된 혼합 모드 어셈블리가 있습니다. 이것은 MFC 확장 dll이며 런타임에 MFC 실행 파일에로드되며 모든 것이 잘 동작합니다. 단위 테스트시 ModuleLoadExceptionHandlerException이 나타나는 이유
우리가 다른 C++/CLI 어셈블리에서 거기에서 관리되지 않는 클래스를 단위 테스트에 와서
, 우리는 우리가 관리되지 않는 클래스의 (새를 통해) 인스턴스를 만들려고 할 때마다 다음과 같은 예외를 참조하십시오Exception
System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> <CrtImplementationDetails>.ModuleLoadExceptionHandlerException: A nested exception occurred after the primary exception that caused the C++ module to fail to load.
---> System.Runtime.Serialization.SerializationException: Serialization error.
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie)
at <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr , Void*)
at <CrtImplementationDetails>.LanguageSupport.InitializeDefaultAppDomain(LanguageSupport*) in f:\dd\vctools\crt_bld\self_x86\crt\src\mstartup.cpp:line 518
at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport*) in f:\dd\vctools\crt_bld\self_x86\crt\src\mstartup.cpp:line 721
at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*) in f:\dd\vctools\crt_bld\self_x86\crt\src\mstartup.cpp:line 875
--- End of inner exception stack trace ---
at <CrtImplementationDetails>.ThrowNestedModuleLoadException(Exception innerException, Exception nestedException)
at <CrtImplementationDetails>.ThrowNestedModuleLoadException(Exception , Exception)
at <CrtImplementationDetails>.LanguageSupport.Cleanup(LanguageSupport* , Exception innerException) in f:\dd\vctools\crt_bld\self_x86\crt\src\mstartup.cpp:line 841
at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport*) in f:\dd\vctools\crt_bld\self_x86\crt\src\mstartup.cpp:line 883
at .cctor() in f:\dd\vctools\crt_bld\self_x86\crt\src\mstartup.cpp:line 922
--- End of inner exception stack trace ---
at MSMContactDataTests.LoadUnknownItemTest()
이것은 테스트 러너 (이 경우 Gallio.Echo)가 어셈블리를로드하지 못하는 것처럼 보입니다.
나는 또한 작은 C++/CLI 콘솔 앱을 만들었고 효과적으로 동일한 것을 시도했다. 어셈블리에 포함 된 ref 클래스의 인스턴스를 올바르게 작성할 수는 있지만 unmanged 클래스를 새로 작성할 때 동일한 예외가 발생합니다.
아이디어가 있으십니까?
편집
내가 여기 파산 콘솔 응용 프로그램 코드를 게시하려고했지만, 나는 그것을 다시 컴파일하고 지금 작동한다! 여기있다 : 그것은 나누기
#include "stdafx.h"
#include "PBSMSDataStoreUnitTests2.h"
#include "SCacheAssignment.h"
using namespace PBSMSDataStoreUnitTests2;
void Class1::SomeTest()
{
Console::WriteLine(L"Hello World");
SCacheAssignment* assignment = new SCacheAssignment(NULL, false);
assignment->id = 2;
Console::WriteLine(L"Hello World 2 " + assignment->id);
}
:
나는 그의 코드를 사용#include "stdafx.h"
using namespace System;
#include "SCacheAssignment.h"
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
SCacheAssignment* assignment = new SCacheAssignment(NULL, false);
assignment->id = 2;
Console::WriteLine(L"Hello World 2 " + assignment->id);
return 0;
}
는 단위 테스트입니다. 이것은 테스트 어셈블리의 유일한 테스트입니다.
콘솔 응용 프로그램은 CLR 클래스 라이브러리에있는 테스트 어셈블리가있는 CLR 콘솔 응용 프로그램입니다. 내가 알 수있는 한, 그들은 동일한 컴파일러 옵션을 사용합니다. 왜 그 중 하나가 작동합니까?
예, 테스트 어셈블리는 C++/CLI에도 있습니다. 게시물을 편집하여 중단되는 테스트 콘솔 앱 코드를 포함시킵니다. –
흥미로운 링크. 고맙습니다. –
Colin, DLL에 전역 생성자가 있습니까? –