Immediate Window, "The expression cannot be evaluated...."

Tomas picture Tomas · May 3, 2011 · Viewed 27.3k times · Source

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.

Answer

bflow1 picture bflow1 · Oct 27, 2011

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.