c# - 在 System.Type 上使用条件断点时出错

标签 c# conditional-breakpoint

这是函数:

public void Init(System.Type Type) {
    this.Type = Type;
    BuildFieldAttributes();
    BuildDataColumns(FieldAttributes);
}

我在第一行设置了一个断点 (this.Type = Type),我想在 Type.FullName == "Malt.Organisation" 时中断这就是我输入的条件。

但是当命中该行时会显示以下错误:

The condition for a breakpoint failed to execute. The condition was 'Type.FullName == "Malt.Organisation"'. The error returned was 'Inspecting the state of an object in the debuggee of type System.Type is not supported in this context.'

我做错了什么(明显的)事情?

附言。解决方法是将其添加到代码中:

if (Type.FullName == "Malt.Organisation") System.Diagnostics.Debugger.Break();

最佳答案

⚠ 注意,自 Visual Studio 2022 以来似乎不再可用。


在我的案例中,我使用的是 Visual Studio 2013、NUnit 2.6.4,并将调试器附加到单元测试 session ,我收到了类似的消息:

The condition for a breakpoint failed to execute. The condition was 'type.Name.Contains("FooBar")'. The error returned was 'Inspecting the state of an object in the debuggee of type System.Type is not supported in this context.'. Click OK to stop at this breakpoint.

这显然是由 Microsoft 引入的新调试引擎中缺少的功能引起的。按照 this msdn blogpost 的说明进行操作我有事情要做。说明归结为:

  1. 从“工具”菜单打开“选项
  2. 在左侧选择“Debugging”、“General
  3. 一直向下滚动以选中“使用托管兼容模式

这应该切换到旧版调试引擎,在我的例子中,它允许在断点条件下使用 Type 表达式。请注意,您确实需要重新启动您的应用或调试 session ,这很明显。

免责声明:我不知道检查这个选项还有什么其他影响。就个人而言,当我完成需要它的任务时,我将其关闭...

关于c# - 在 System.Type 上使用条件断点时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32276732/

相关文章:

c++ - 特定模板参数的模板断点

objective-c - 是否可以将符号断点(或类似断点)与动态属性 setter 一起使用?

c# - 如何继承NuGet包中引用的程序集

c# - DateTimePicker 获取焦点字段

c# - 如何让单元测试知道 Application.Resources

c# - 如何降低统一的不透明度?

java - Eclipse 条件断点,在任何字符串等于

eclipse - 将条件断点与 instanceof 一起使用时出错。是我还是 eclipse ?

c++ - 什么是数据断点?

c# - 如何读取 Xamarin Forms PCL 项目中的文本文件?