Sometimes when I quickwatch an expression at runtime, the Quick Watch window shows an error saying the name does not exists in the current context. The same goes for the immediate window. The expression I try to evaluate, however, is perfectly recognized by the class, without throwing any compilation error.
For example, I can have the following line of code:
double x = Math.Pow(2,3);
If I stop the cursor on this line and quickwatch the "Math.Pow(2,3)" part, it gives me an error and I need to place a "System." before my expression; as I said, the same expression runs smoothly in the code window, so I'm not sure which is the "context" the error refers to.
Could it be that these debug windows reference namespaces declared in the class but can't do the same for namespace imported by the project?
To display the Immediate window, open a project for editing, and then choose Debug > Windows > Immediate or press Ctrl+Alt+I. You can also enter Debug. Immediate in the Command window. The Immediate window supports IntelliSense.
To execute code in the Immediate window Use the Immediate window to: Test problematic or newly written code. Query or change the value of a variable while running an application. While execution is halted, assign the variable a new value as you would in code.
In my understanding the QuickWatch and the Immediate windows are executing the code / expressions under the current executing context, so once there is a using System;
in place in the code, the quickwatch window will not give any issue. You may have encountered some visual studio bug. Try restarting VisualStudio and check again.
I have not encountered this kind of issue. This kind of issue will crop up when you try to Quick Watch Math.Pow(2d, 4d);
when having the code like this System.Math.Pow(2d, 4d);
Solution:
Go to your program.cs file and add the usings you want your immediate window to use, this works for both Console and Windows Forms applications
Refrence namespaces to Immediate Window in a Class Library Project
If you are using the Immediate Window in "Design Time" mode, and want reference some namespaces to it, you need to set the ouput mode to Windows Application, and create a program that does nothing.
Program.cs
using System; //Add all the refrences you need immediate window to use here namespace YourNamespace { static class Program { static void Main() { } } }
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