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クラスのインスタンスを正しく作成できますが、アンマウントされたクラスを新規にしようとすると、同じ例外が発生します。
アイデア?
EDIT
私はここで破ったコンソールアプリケーションのコードを投稿するつもりだったが、私はそれを再コンパイルして、それが機能するようになりました!ここにある:それは壊れる
#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コンソールアプリケーションです。私が知る限り、彼らは同じコンパイラオプションを使用します。なぜ1人は働き、1人は働かないのですか?
はい、テストアセンブリはC++/CLIにもあります。投稿を編集して、破損したテストコンソールのアプリコードを追加します。 –
興味深いリンク。ありがとうございました。 –
Colin、DLLにグローバルコンストラクタがありますか? –