Alex Rivera | Logout

Visual Studio Watch window not taking into account usings

Asked 2012-02-29T02:15:50.553
9

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
Report

1 Answer

6

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

answered 2012-02-29T05:52:58.987

Your Answer