Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Error: "Name '__o' is not declared."

Tags:

asp.net-mvc

I've got a whole bunch of these errors on my View aspx file.

But, It builds and runs just fine.

What are they? How do I get rid of them?

like image 607
Zack Peterson Avatar asked Mar 13 '09 16:03

Zack Peterson


1 Answers

Mikhail Arkhipov posted an explanation and workaround in the ASP.NET forums:

We have finally obtained reliable repro and identified the underlying issue. A trivial repro looks like this:

<% if (true) { %>
    <%=1%>
<% } %>
<%=2%>

In order to provide intellisense in <%= %> blocks at design time, ASP.NET generates assignment to a temporary __o variable and language (VB or C#) then provide the intellisense for the variable. That is done when page compiler sees the first <%= ... %> block. But here, the block is inside the if, so after the if closes, the variable goes out of scope. We end up generating something like this:

if (true) { 
    object @__o;
    @__o = 1;
}
@__o = 2;

The workaround is to add a dummy expression early in the page. E.g. <%="" %>. This will not render anything, and it will make sure that __o is declared top level in the Render method, before any potential ‘if’ (or other scoping) statement.

like image 146
Zack Peterson Avatar answered Oct 19 '22 21:10

Zack Peterson