简体   繁体   English

Visual Studio Watch窗口没有考虑使用

[英]Visual Studio Watch window not taking into account usings

I have the following code in a view model: 我在视图模型中有以下代码:

public Point Location
{
    get
    {
        var rangePixels = Range * PixelsPerMile;
        var xCoordinate = OwnLocation.X * MapScale + rangePixels * Math.Cos(Theta);
        var yCoordinate = OwnLocation.Y * MapScale - rangePixels * Math.Sin(Theta);
        return new Point(xCoordinate, yCoordinate);
    }
}

One of the usings at the top of the code file is System , which contains Math . 代码文件顶部的一个用法是System ,它包含Math

If I view Math.Sin(Theta) in the Watch window (by selecting the code, right clicking, and choosing "Add Watch"), I get the following error: 如果我在Watch窗口中查看Math.Sin(Theta) (通过选择代码,右键单击并选择“Add Watch”),我收到以下错误:

The name 'Math' does not exist in the current context 当前上下文中不存在名称“Math”

What I want to know is: 我想知道的是:

  1. Is this expected/default behavior for Visual Studio 2010? 这是Visual Studio 2010的预期/默认行为吗? I could swear this never used to be a problem, but maybe it's always worked that way and I somehow never noticed. 我可以发誓这从来不是一个问题,但也许它总是那样工作,我不知何故从来没有注意到。
  2. If it's not normal to get this error, any thoughts on what the problem could be? 如果得到这个错误是不正常的,那么对问题可能是什么的任何想法? There are a million settings in Visual Studio, and I wouldn't know where to begin. Visual Studio中有一百万个设置,我不知道从哪里开始。

I should note this question is vaguely similar to this , but I'm not having any issues mousing over my local variables, and I'm not using PostSharp. 我应该注意到这个问题与类似,但我没有任何问题将鼠标置于我的局部变量上,而且我没有使用PostSharp。

Edit 编辑

I just tried resetting all my Visual Studio settings backs to default, and I'm still getting the same error. 我只是尝试将我的所有Visual Studio设置重置为默认值,但我仍然遇到同样的错误。 If someone wants to try a simple test in Visual Studio, I just want to know if you get an error if you add a watch for Math.Sin(1) . 如果有人想在Visual Studio中尝试一个简单的测试,我只想知道如果你为Math.Sin(1)添加一个手表就会出现错误。

Edit 2 编辑2

Here are a couple screen captures to show what I'm experiencing: 这里有几个屏幕截图,以显示我正在经历的:

添加Math.Sin(1)来观看

显示Watch的错误

Edit 3 编辑3

Interestingly, intellisense works if I type Math. 有趣的是,如果我输入Math. ,intellisense就有效Math. into the Watch window, but if I complete the expression, I still get the error: 进入Watch窗口,但如果我完成表达式,我仍然会收到错误:

显示intellisense工作

Edit 4 编辑4

To address BACON's questions: 解决BACON的问题:

  1. I get the same behavior with QuickWatch and Immediate. 我使用QuickWatch和Immediate获得相同的行为。
  2. Closing and reopening all the windows does not solve the problem. 关闭并重新打开所有窗口并不能解决问题。
  3. I'm using Visual Studio 2010 Professional (version 10.0.40219.1 SP1Rel) 我正在使用Visual Studio 2010 Professional(版本10.0.40219.1 SP1Rel)
  4. I tried targeting .NET 4.0 Client Profile and full .NET 4.0. 我尝试针对.NET 4.0 Client Profile和完整的.NET 4.0。 Made no difference. 没有区别。 I created a Console App (rather than a WPF app) targeting .NET 4.0 Client Profile, and finally, the error did not occur. 我创建了一个针对.NET 4.0 Client Profile的Console App(而不是WPF应用程序),最后,没有发生错误。 So, WPF may be an issue (or WPF with some third-party libraries). 因此,WPF可能是一个问题(或WPF与一些第三方库)。 (Will check on that next.) (接下来会检查。)

It appears that the culprit is a third-party library that performs IL weaving (Fody.PropertyChanged). 罪魁祸首似乎是执行IL编织的第三方库(Fody.PropertyChanged)。

If I create a new WPF project without this library, I'm able to use Math.Sin() in the Watch window. 如果我创建一个没有这个库的新WPF项目,我可以在Watch窗口中使用Math.Sin() Once I install PropertyChanged , I start getting the "not available in this context" error. 安装PropertyChanged ,我开始收到“在此上下文中不可用”错误。

Thanks to @BACON for leading me down the right path to figuring this out. 感谢@BACON引导我走上正确的道路来解决这个问题。

Here's a link to an issue I posted on the PropertyChanged site: 这是我在PropertyChanged网站上发布的问题的链接:

http://code.google.com/p/propertychanged/issues/detail?id=6&thanks=6&ts=1330494634 http://code.google.com/p/propertychanged/issues/detail?id=6&thanks=6&ts=1330494634

Edit 编辑

And subsequently, it turns out this is probably a bug in Mono-Cecil, which PropertyChanged uses: 随后,事实证明这可能是Mono-Cecil中的一个错误,PropertyChanged使用它:

https://github.com/jbevain/cecil/issues/90 https://github.com/jbevain/cecil/issues/90

I did this in a litte test app, in the constructor.. 我是在一个litte测试应用程序中,在构造函数中完成的。

在此输入图像描述

Trying to put a watch on Math lets me see the values of E and PI. 试着把手表放在数学上可以让我看到E和PI的值。 You cannot put one on Sin. 你不能把一个放在罪上。 Putting one on val works just fine. 把一个放在val上就可以了。

So, no, I don't think that it's quite normal, unless you clicked on the wrong name. 所以,不,我不认为这是正常的,除非你点击了错误的名字。 Ie, not the variable, but the "Sin" portion... 即,不是变量,而是“罪”部分......

Here is where I highlighted the entire thing... 这是我突出整个事情的地方......

在此输入图像描述

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

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