Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Studio Watch window not taking into account usings
    text
    copied!<p>I have the following code in a view model:</p> <pre><code>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); } } </code></pre> <p>One of the usings at the top of the code file is <code>System</code>, which contains <code>Math</code>.</p> <p>If I view <code>Math.Sin(Theta)</code> in the Watch window (by selecting the code, right clicking, and choosing "Add Watch"), I get the following error:</p> <blockquote> <p>The name 'Math' does not exist in the current context </p> </blockquote> <p>What I want to know is:</p> <ol> <li>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.</li> <li>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.</li> </ol> <p>I should note this question is vaguely similar to <a href="https://stackoverflow.com/questions/8672620/out-of-context-variables-in-visual-studio-2010-debugger">this</a>, but I'm not having any issues mousing over my local variables, and I'm not using PostSharp.</p> <p><strong>Edit</strong></p> <p>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 <code>Math.Sin(1)</code>.</p> <p><strong>Edit 2</strong></p> <p>Here are a couple screen captures to show what I'm experiencing:</p> <p><img src="https://i.stack.imgur.com/DaDRk.png" alt="Adding Math.Sin(1) to watch"></p> <p><img src="https://i.stack.imgur.com/ta6yQ.png" alt="Showing error for Watch"></p> <p><strong>Edit 3</strong></p> <p>Interestingly, intellisense works if I type <code>Math.</code> into the Watch window, but if I complete the expression, I still get the error:</p> <p><img src="https://i.stack.imgur.com/7OkDT.png" alt="Showing intellisense working"></p> <p><strong>Edit 4</strong></p> <p>To address BACON's questions:</p> <ol> <li>I get the same behavior with QuickWatch and Immediate.</li> <li>Closing and reopening all the windows does not solve the problem.</li> <li>I'm using Visual Studio 2010 Professional (version 10.0.40219.1 SP1Rel)</li> <li>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.)</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload