Answered by:
'__o' is not declared - what does it mean?

Question
-
User-376234351 posted
I have a web page that has 21 errors all pointing to the same place and each error is the same as this first one::
Error 1 Name '__o' is not declared. C:\Data\Artwork\web sites\MRL Insurance Direct Web Site\web-content\affiliate\stats1.aspx 97 1 C:\...\web-content\
What does it mean?Thursday, September 29, 2005 11:25 AM
Answers
-
User-1363174918 posted
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.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 20, 2006 5:37 PM
All replies
-
User1119954915 posted
So what is the code on line 97 in stats1.aspxThursday, September 29, 2005 2:59 PM -
User-376234351 posted
This:
</script>
Thursday, September 29, 2005 3:07 PM -
User-376234351 posted
Here's a screen-grab showing the problem:
http://www.gilkes.me.uk/aspnet/01.html
(its now line 88 as I've made some changes to the script)Thursday, September 29, 2005 3:14 PM -
User-1363174918 posted
ASP.NET runtime generates a few internal class members that are necessary to support inline expressions like <%# %>. There is something wrong with the code that is not visible to you. It would be useful if you could post the entire page markup.Monday, October 3, 2005 2:24 PM -
User-376234351 posted
Mikhail
Thanks for your reply. Unfortunately (or should that be fortunately) the errors no longer show in the Error list.
I had made some changes to the page (which involved removing some inline code) and the errors disappeared.
At least I know what causes the errors now. Perhaps they should be better documented than just "__o"
Regards
StephenWednesday, October 5, 2005 11:03 AM -
User-885951438 posted
I just ran across the same issue. What I was trying to do was to do inline conditional display of HTML:
<%
If valueCountyName <> "" Then
%>
<DIV align=left><STRONG> Multi-Jurisdiction: <FONT
color=maroon><%=valueCountyName%></FONT></STRONG></DIV>
<%
End If
%>
With this in place, ever <%=whatever%> below this resulted in the error. But the page would render correctly in the browser and there was no problem at runtime. When I took out the "If" from around the DIV, the errors went away.
Why can't I do this in ASP.NET? I know it is old school ASP Classic style, but it still should work.
(trying this in Microsoft Visual Studio 2005 Version 8.0.50215.44)Wednesday, November 9, 2005 8:57 AM -
User-916962509 posted
Sorry to re-open an old thread, but I am having this problem using Visual Studio 2005 8.0.50727.42:
Here is my markup:
<div id="ContentBox4" class="ContentBox">
The most requested items:-
<ul>
<% For Each drow As Data.DataRow In ServiceInteraction.Service.ItemOffers_Get_Top5Requests.Tables(0).Rows
' Work out how long ago it was posted:
Dim timePosted As TimeSpan = Now.Subtract(CDate(drow.Item("dateListed")))
%>
<li>
<a href="ViewItem/ViewItem.aspx?ItemID=<%=drow.item("itemID")%>">
<%=drow.Item("itemName")%></a> [in <%=drow.Item("categoryName")%>]
<br />
<em><%=drow.Item("requests")%>
<% If CInt(drow.Item("requests")) = 1 Then%>
request.
<% Else%>
requests.
<% end if %>
</em>
<br />
<%
If timePosted.Days > 0 Then
Response.Write("...... " & timePosted.Days & " days and " & timePosted.Hours & " hours ago")
ElseIf timePosted.Hours = 0 AndAlso timePosted.Days = 0 Then
Response.Write("...... " & timePosted.Minutes & " minutes ago")
Else
Response.Write("...... " & timePosted.Hours & " hours ago")
End If
%>
</li>
<%Next%>
</ul>
</div>
I am getting blue-squiggly line and the error "Name __o is not declared" on the following lines:
- The first <li>
- <%=drow.Item("itemName")%>
- <%=drow.Item("categoryName")%>
- <%=drow.Item("requests")%>
Similar to the above posts, this shows as a build error in the IDE - yet the project builds fine ("Build Succeeded" and it looks exactly right in browsers.
Best wishes,
Ben.Monday, February 6, 2006 6:23 AM -
User-1363174918 posted
If I only use the pasted markup, I see a single error:
Error 1 Name 'ServiceInteraction' is not declared.
I did some general editing for a few minutes, but was unable to repro the error. I guess there might be something in the site structure.
Tuesday, February 7, 2006 12:12 AM -
User-916962509 posted
Hi.
Thank you for your reply.
ServiceInteraction is a class within the same namespace. As you might expect; it contains methods to interact with a web service.
I have put a screenshot of Visual Studio in "Markup View" mode at http://uni.bgs.me.uk/onotdefined.jpg - the page this markup generates is at http://uni.bgs.me.uk/FreeBay/default.aspx in case you want to see that, also.
What did you mean by "might be something in the site structure"? Something like what?
Again, thanks for looking at this.
Ben.
Friday, February 10, 2006 2:27 PM -
User-1363174918 posted
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.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, April 20, 2006 5:37 PM -
User-916962509 posted
Hi Mikhail,
Thank you for addressing this issue and finding a workaround. I will try it in a few hours.
All the best,
BenFriday, April 21, 2006 5:18 AM -
User-14960048 posted
<% response.write(var) %> instead of <% =var %> removes the error without declaring __o as suggested before...
:Drewman
Monday, April 24, 2006 12:07 AM -
User104367873 posted
Try a bit unconventional thinking.
If your intellisense variable is out of scope, then you can simply create the variable in your class/page/module and the warning/error goes away.
Simply add:
Public __o As Object ' VB.net
public object __o ; // C#
Thursday, October 29, 2009 5:04 AM -
User1175915098 posted
Public __o As Object does not work in my case as I already have it declared in my .vb file.
Adding <%= __o%> outside the IF block works, but that causes the variable to display. Am I missing something?
Thursday, November 5, 2009 2:52 PM -
User104367873 posted
It always outputs, if you have a <%= something%>
try remove the = and write a declaration instead
Saturday, November 14, 2009 4:38 PM -
User486328453 posted
<%=""> perfect. Now that is something that should be documented within VS. Nice fix.
Tuesday, November 17, 2009 7:20 PM -
User-1400379606 posted
Thanks guys. I had an inital <%=%> inside a div that is RunAt=Server. That also causes a problem. Mikhails problem fixed it straight away.
Thanks alot.
greg
Friday, April 23, 2010 10:25 AM