简体   繁体   English

如何让Visual Studio 2017以交互方式调试此行?

[英]How can I get Visual Studio 2017 to interactively debug this line?

I have the following code set up as a dummy example to illustrate what I found in my production code. 我将以下代码设置为一个虚拟示例,以说明我在生产代码中找到的内容。

static void Main(string[] args)
{
    bool GreaterThan(int x, int y)
    {
        return x > y;
    }

    bool OperateOnTwoNumbers(int x, int y, Func<int, int, bool> func)
    {
        return func(x, y);
    }

    var twoGreaterThanOne = OperateOnTwoNumbers(2, 1, GreaterThan);

}

When I set a watch, or interatively debug with Shift+F9 , on OperateOnTwoNumbers(2, 1, GreaterThan) , I get the following error. 当我在OperateOnTwoNumbers(2, 1, GreaterThan)上设置手表或使用Shift + F9进行OperateOnTwoNumbers(2, 1, GreaterThan)调试时,出现以下错误。

OperateOnTwoNumbers(2, 1, GreaterThan) error CS0103: The name 'OperateOnTwoNumbers' does not exist in the current context OperateOnTwoNumbers(2,1,GreaterThan)错误CS0103:当前上下文中不存在名称“OperateOnTwoNumbers”

But the code itself runs fine, and after I step over the line, I can see the value assigned to the variable. 但代码本身运行正常,在我跨过该行后,我可以看到分配给变量的值。

This has been replicated on more than one computer, with the production code and with this dummy example, so I don't think it's an environment issue. 这已在多台计算机上复制,包含生产代码和虚拟示例,因此我认为这不是一个环境问题。

Here is a recording of the issue, it can be viewed in full quality by clicking on the recording and viewing it at its direct address. 这是一个问题的录音,可以通过点击录音并在其直接地址查看来全面查看。

记录问题

Any ideas? 有任何想法吗?

I suspect that watch expression evaluator has not yet been updated to handle local functions (or, if it works in some versions of VS and doesn't in others - has not been updated in your specific version). 我怀疑表达式评估程序尚未更新以处理本地函数(或者,如果它在某些版本的VS中有效,而在其他版本中没有 - 在您的特定版本中尚未更新)。

Local functions (like GreaterThan and OperateOnTwoNumbers ) are just syntax sugar and really compiled into static functions with cryptic names: 本地函数(如GreaterThanOperateOnTwoNumbers )只是语法糖,并且真正编译成具有神秘名称的静态函数:

[CompilerGenerated]
internal static bool <Main>g__OperateOnTwoNumbers|0_1(int x, int y, Func<int, int, bool> func)
{
  return func(x, y);
}

And call to them is then: 然后打电话给他们:

Program.<Main>g__OperateOnTwoNumbers|0_1(...);

So watch expression evaluator should realize that, but it doesn't and tries to call function with OperateOnTwoNumbers name (as you can see from compiler error message "The name 'OperateOnTwoNumbers' does not exist in the current context"), and there is really no such function. 所以表达式求值程序应该意识到,但它没有并尝试用OperateOnTwoNumbers名称调用函数(从编译器错误消息中可以看到“名称'OperateOnTwoNumbers'在当前上下文中不存在”),并且确实存在没有这样的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM