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:
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:
Edit 3
Interestingly, intellisense works if I type Math.
into the Watch window, but if I complete the expression, I still get the error:
Edit 4
To address BACON's questions:
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
I did this in a litte test app, in the constructor..
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With