2009-07-16 25 views
4

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人は働かないのですか?

答えて

1

ユニットテストアセンブリもC++/CLIですか? (新たな情報に基づいて編集した)

興味をそそります。私は混在モードのDLLで失敗した管理静的コンストラクタが原因である可能性がありますか?または、グローバルなネイティブ変数を作成する際に何か問題がありますか?

私は、この接続の問題で、同じ問題への言及が見つかりました: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=316549

しかし、誰溶液または適切な診断を、私は怖いです。

+0

はい、テストアセンブリはC++/CLIにもあります。投稿を編集して、破損したテストコンソールのアプリコードを追加します。 –

+0

興味深いリンク。ありがとうございました。 –

+0

Colin、DLLにグローバルコンストラクタがありますか? –

関連する問題