The Immediate Window: Working with Members
Keyboard: CTRL + ALT + I
Menu: Debug -> Windows -> Immediate
Command: Debug.Immediate
Versions: 2008,2010
Published: 9/28/2010
Code: vstipTool0095
When using with the Immediate Window, you can work with class and object members directly:
Debug
You can use any method or property as long as it is in context. So, for example, when you are in debug mode, you can call any method that is in scope:
Design
A less-known feature is you can work with properties and methods while in design mode. If you have static methods on a class, for example, you can just execute them right away:
For object members, obviously, you need to create an instance of the object before working with the members:
WARNING: When working with members at design-time a build will occur. This could have unintended consequences so make sure you have experimented with this feature a bit before you use it.
Comments
Anonymous
September 28, 2010
What can I do in the immediate window when I am in native C/C++ code?Anonymous
September 28, 2010
Design time debugging doesn't work for me. I have a public static method (all it does is writes "test" to the output window), and I get the following message: The expression cannot be evaluated while in design mode. Am I missing a studio setting somewhere to enable this?Anonymous
September 28, 2010
The comment has been removedAnonymous
September 30, 2010
@Aaron, @Zeinab - same thing for me. I have productivity tools installed, added a simple class with the static method, and tried to call it while in design mode. The result - like in @Aaron case :( Any help? Thanks!Anonymous
September 30, 2010
Weird. Let me poke around and see if this is a known issue.Anonymous
October 01, 2010
Zain, if you figure it out, could you just write a new post on it? I think it's a fantastic feature that many folks would benefit from. Thanks for all of you contributions, you rock!Anonymous
October 12, 2010
Same problem as Aaron... I'm running Visual Studio 2010, and have a simple asp.net app. I've created a class file (VB) with a public method. When I type in the Immediate window, the intellisense works and finds class_name.function_name(), and it responds "The expression cannot be evaluated while in design mode." Trying to run in Debug mode says "The expression cannot be evaluated while in run mode." Thanks!Anonymous
October 14, 2010
I'm having the same problem as Geoff and Aaron. I have a native C++ DLL built in VS 2010. I tried executing an exported static function or even a simple expression like 2+3, and I get "The expression cannot be evaluated while in design mode." I also tried running another project in the same solution as the DLL in Debg mode, but I got, "The expression cannot be evaluated while in run mode."Anonymous
December 14, 2010
@Aron, @ms440m, @Geoff: Not quite sure if this can be helpful: msdn.microsoft.com/.../f177hahy(v=vs.80).aspx Design Time Expression Evaluation in Multi-Project Solutions When establishing the context for design time expression evaluation, Visual Studio references the currently selected project in Solution Explorer. If no project is selected in Solution Explorer, Visual Studio attempts to evaluate the function against the startup project. If the function cannot be evaluated in the current context, you will receive an error message. If you are attempting to evaluate a function in a project that is not the startup project for the solution and you receive an error, try selecting the project in Solution Explorer and attempt the evaluation again. Keep in mind that if you are working with Web Applications you need to debug your app and hit a breakpoint (just place a breakpoint on your start page of the project) before evaluating from the immediate window. Otherwise you will be greeted with " The expression cannot be evaluated while in design mode." or "The expression cannot be evaluated while in run mode. " Hope it helps.Anonymous
April 12, 2011
Hey All -- just retested this with shared/static methods in VB/C# and it does work for those scenarios. It does not work in C++ as near as I can tell. The C# example is just like the one in the post. The VB example class looks like this: Class Jack Shared Function DoSomething() Return 10 End Function End Class And this is what I put into the Immediate Window from Design Mode(with the result shown as well): ?Jack.DoSomething() 10 {Integer} Integer: 10Anonymous
February 14, 2012
When in design mode, just rebuild your solution, and you can test anything from your solution in the immediate window. As simple as that.Anonymous
July 07, 2014
@Aaron - did you resolve the complete name for static function you called in Immediate window ? - I initially had that error and then resolved when I resolved the call with the complete name .. AssmeblyName.Namespace.ClassName.FunctionCall(arguments)