Oct 03, 2005 02:24 PM|Mikhail Arkhipov (MSFT)|LINK
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.
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)
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")%>
Thanks in advance for any advice anybody can offer.
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.
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?
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.
None
0 Points
148 Posts
'__o' is not declared - what does it mean?
Sep 29, 2005 11:25 AM|gilkesy|LINK
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?
Participant
1316 Points
1790 Posts
Re: '__o' is not declared - what does it mean?
Sep 29, 2005 02:59 PM|MorningZ|LINK
None
0 Points
148 Posts
Re: '__o' is not declared - what does it mean?
Sep 29, 2005 03:07 PM|gilkesy|LINK
</script>
None
0 Points
148 Posts
Re: '__o' is not declared - what does it mean?
Sep 29, 2005 03:14 PM|gilkesy|LINK
http://www.gilkes.me.uk/aspnet/01.html
(its now line 88 as I've made some changes to the script)
All-Star
15482 Points
6040 Posts
Re: '__o' is not declared - what does it mean?
Oct 03, 2005 02:24 PM|Mikhail Arkhipov (MSFT)|LINK
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
None
0 Points
148 Posts
Re: '__o' is not declared - what does it mean?
Oct 05, 2005 11:03 AM|gilkesy|LINK
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
Stephen
None
0 Points
1 Post
Re: '__o' is not declared - what does it mean?
Nov 09, 2005 08:57 AM|GnosticTom|LINK
<%
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)
Member
686 Points
208 Posts
Re: '__o' is not declared - what does it mean?
Feb 06, 2006 06:23 AM|bgs264|LINK
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:
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.
All-Star
15482 Points
6040 Posts
Re: '__o' is not declared - what does it mean?
Feb 07, 2006 12:12 AM|Mikhail Arkhipov (MSFT)|LINK
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.
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Member
686 Points
208 Posts
Re: '__o' is not declared - what does it mean?
Feb 10, 2006 02:27 PM|bgs264|LINK
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.
All-Star
15482 Points
6040 Posts
Re: '__o' is not declared - what does it mean?
Apr 20, 2006 05:37 PM|Mikhail Arkhipov (MSFT)|LINK
<% 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.
------------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Member
686 Points
208 Posts
Re: '__o' is not declared - what does it mean?
Apr 21, 2006 05:18 AM|bgs264|LINK
Thank you for addressing this issue and finding a workaround. I will try it in a few hours.
All the best,
Ben
None
0 Points
9 Posts
Re: '__o' is not declared - what does it mean?
Apr 24, 2006 12:07 AM|deeman|LINK
<% response.write(var) %> instead of <% =var %> removes the error without declaring __o as suggested before...
:Drewman
None
0 Points
35 Posts
Re: '__o' is not declared - what does it mean?
Oct 29, 2009 05:04 AM|tux|LINK
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#
Member
1 Points
77 Posts
Re: '__o' is not declared - what does it mean?
Nov 05, 2009 02:52 PM|Laplain|LINK
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?
None
0 Points
35 Posts
Re: '__o' is not declared - what does it mean?
Nov 14, 2009 04:38 PM|tux|LINK
It always outputs, if you have a <%= something%>
try remove the = and write a declaration instead
None
0 Points
3 Posts
Re: '__o' is not declared - what does it mean?
Nov 17, 2009 07:20 PM|msandfox|LINK
<%=""> perfect. Now that is something that should be documented within VS. Nice fix.
None
0 Points
1 Post
Re: '__o' is not declared - what does it mean?
Apr 23, 2010 10:25 AM|gamcfarlane|LINK
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