在System.Type上使用条件断点时出错 [英] Error when using a conditional breakpoint on System.Type

查看:129
本文介绍了在System.Type上使用条件断点时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是函数:

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

我已经在第一行设置了一个断点( this.Type =类型),我想在 Type.FullName == Malt.Organisation 时打破,所以我输入了

I've set a breakpoint on the first line (this.Type = Type) and I want to break when Type.FullName == "Malt.Organisation" so that's what I've entered in as the condition.

但是,在点击该行时会显示以下错误:

However the following error is displayed when the line is hit:


断点的条件无法执行。条件是
‘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.'

我做错了什么(显而易见)?

What (obvious) thing am I doing wrong?

PS。一种解决方法是将其添加到代码中:

PS. A workaround is to add this to the code:

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


推荐答案

我使用的是Visual Studio 2013,NUnit 2.6.4,并将调试器附加到单元测试会话,我得到了类似的消息:

In my case I was using Visual Studio 2013, NUnit 2.6.4, and attaching a debugger to a unit test session, and I was getting a similar message:


断点的条件失败执行。条件是 type.Name.Contains( FooBar)'。返回的错误是在类型为System.Type的调试对象中检查对象的状态。单击确定以在此断点处停止。

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引入的新调试引擎中缺少功能所致。请遵循此msdn博客文章我有工作需要。指示可归结为:

This was caused by a missing feature in the new debug engine Microsoft had introduced, apparently. Following instructions from this msdn blogpost I got things to work. The instructions boil down to:


  1. 工具菜单中打开 选项

  2. 在左侧选择 调试常规

  3. 滚动一直向下滚动以检查 使用托管兼容模式

  1. From the "Tools" menu open "Options"
  2. On the left hand side pick "Debugging", "General"
  3. Scroll all the way down to check "Use Managed Compatibility Mode"

这应该切换到旧式调试引擎,在我的情况下,该引擎允许在断点条件下使用Type的表达式。注意,显然,您确实需要重新启动应用程序或调试会话。

This should switch to the legacy debug engine, which in my case allowed for expressions on Type in break point conditions. Note that you do need to restart your app or debugging session, obviously.

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

Disclaimer: I have no idea what other effects checking this option had. Personally, I turned it back off when I was done with the task that required it...

这篇关于在System.Type上使用条件断点时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆