Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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:

The name 'Math' does not exist in the current context

What I want to know is:

  1. Is this expected/default behavior for 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.

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.

Edit

I just tried resetting all my Visual Studio settings backs to default, and I'm still getting the same error. 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).

Edit 2

Here are a couple screen captures to show what I'm experiencing:

Adding Math.Sin(1) to watch

Showing error for Watch

Edit 3

Interestingly, intellisense works if I type Math. into the Watch window, but if I complete the expression, I still get the error:

Showing intellisense working

Edit 4

To address BACON's questions:

  1. I get the same behavior with QuickWatch and 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)
  4. I tried targeting .NET 4.0 Client Profile and full .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. So, WPF may be an issue (or WPF with some third-party libraries). (Will check on that next.)
like image 372
devuxer Avatar asked Feb 29 '12 02:02

devuxer


2 Answers

It appears that the culprit is a third-party library that performs IL weaving (Fody.PropertyChanged).

If I create a new WPF project without this library, I'm able to use Math.Sin() in the Watch window. Once I install PropertyChanged, I start getting the "not available in this context" error.

Thanks to @BACON for leading me down the right path to figuring this out.

Here's a link to an issue I posted on the PropertyChanged site:

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:

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

like image 126
devuxer Avatar answered Oct 05 '22 15:10

devuxer


I did this in a litte test app, in the constructor..

enter image description here

Trying to put a watch on Math lets me see the values of E and PI. You cannot put one on Sin. Putting one on val works just fine.

So, no, I don't think that it's quite normal, unless you clicked on the wrong name. I.e., not the variable, but the "Sin" portion...

Here is where I highlighted the entire thing...

enter image description here

like image 29
pennyrave Avatar answered Oct 05 '22 15:10

pennyrave