问题:
我有一个表单项目,它实例化了在另一个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
时,我会得到以下错误信息:无法计算表达式,操作不支持,未知错误: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;
}
你可能已经想象到了,这使得调试我的应用程序变得非常困难 :) 欢迎提供任何帮助。