Reputation: 18097
When I try to evaluate expression in Immediate Window at design time, I get error:
The expression cannot be evaluated while in design mode.
If I compile ASP.NET project and try to run it in debug mode I get another error:
The expression cannot be evaluated while in run mode.
Why do I get these errors? I have used Immediate Window in the past and it worked fine even in design mode.
Upvotes: 45
Views: 34781
Reputation: 13709
As northben pointed out in a comment, if you're trying to access properties in the immediate window while your application is not running, you may get:
The expression cannot be evaluated while in design mode.
Therefore:
GlobalConfiguration.Configuration
) – now this should get you the proper results if that property exists in that context. If it does not exist, then you will get:
The expression cannot be evaluated while in run mode.
It's as simple as making sure you are accessing the properties in the right context.
Upvotes: 4
Reputation: 24366
In my case I received this error while using Excel Interop after enabling native debugging. Then in the debug mode I tried this:
?xlworkbook.sheets(1).name
The process hung, I did not receive any answer, and after that every other thing, e.g. ?2+2
gave me that error:
The expression cannot be evaluated while in run mode
In order to again be able to use debug features, I had to disable native debugging.
Upvotes: 0
Reputation: 133
It's worth noting that the behavior of the Immediate window varies depending on the edition of Visual Studio you are using. If I try to evaluate a simple expression like ? 2+2
in Visual Studio 2013 Express for Web, I receive the "The expression cannot be evaluated while in design mode" error message; however, in Visual Studio 2013 Professional the expression evaluates to 4
without having to be in debug mode.
Upvotes: 6
Reputation: 969
Assuming that you aren't missing the >
operator in the Immediate Window, there could be problems if you are trying to evaluate an expression at design-time in a multi-project solution or even a web project.
According to MSDN:
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.
Also:
You cannot use design time expression evaluation in project types that require starting up an execution environment, including Visual Studio Tools for Office projects, Web projects, Smart Device projects, and SQL projects.
Upvotes: 32