問題: 別のdllプロジェクトで定義されているクラスをインスタンス化するフォームプロジェクトがあります。このdllを使用するフォームアプリケーションを実行すると、すべてが完全に正常に実行されますが、dllプロジェクトで定義されているタイプのオブジェクトを検査するためにブレークポイントを設定すると、ウォッチウィンドウにエラーが表示されます。
知っておくべき重要なこと:
- dllプロジェクトは、安全でない管理されていないコードを使用しています。
- この問題は、安全でない関数が呼び出される前に発生します。
- アンマネージコードのデバッグが有効になっています。
- シンボルがdll用にロードされていることを知っています。
- デバッガーによってロードされるdllのバージョンは、アプリケーションで使用されるものと同じです。
- 出力ディレクトリをクリーンアップして削除してから、再構築しました。
- 彼らは同じ.NETバージョンを使用しています。
例:これをウォッチウィンドウに追加すると、次のように表示MyDllType.SomeProperty
されます(ウォッチウィンドウのみ):
'MyDllType.SomeProperty' threw an exception of type 'System.ArgumentException' Message: "Cannot find the method on the object instance."
ただし、同じ正確なポイントで追加Debug.Writeline(MyDllType.SomeProperty);
した場合、例外は発生せず、出力コンソールに正しく表示されます。
さらに、dllプロジェクトで定義された構造体タイプのリストを作成してウォッチウィンドウに追加すると、次のように表示されます(ウォッチウィンドウのみ)。
// My Dll Project
public struct MyDllStruct
{
public int x;
public int y;
public int z;
}
// Snippet from a function block in forms project
List<MyDllStruct> structList = new List<MyDllStruct>();
// Add a bunch of stuff to the list
// <-- Insert a breakpoint here
}
壊れstructList
てウォッチウィンドウに追加すると、次のようになります。
Unable to evaluate the expression. Operation not supported. Unknown error: 0x8004f0ed.
ただし、もう一度Debug.Writeline(structList.Count);
同じ正確なポイントで追加すると、例外は発生せず、カウントが出力コンソールに正しく表示されます。
完全な例:
// My Dll Project
public class MyDllType
{
public MyDLLType()
{
this.someProperty = 123456;
}
private int someProperty;
public int SomeProperty
{
get{ return this.someProperty; }
set{ this.someProperty = value; }
}
}
public struct MyDllStruct
{
public int x;
public int y;
public int z;
}
// My Forms Project
public class SomeController
{
public SomeController()
{
this.dllType = new DllType();
List<MyDllStruct> structList = new List<MyDllStruct>();
// <-- For example, I get both aformentioned problems if i break here (or anywhere else these objects have been instantiated)
}
private MyDllType dllType;
}
ご想像のとおり、これによりアプリケーションのデバッグが非常に困難になっています:)助けていただければ幸いです。