I just installed Visual Studio 2015 and opened my asp .net project that I was working on. I\'m receiving many errors (all exactly the same) as below:
After reading the links given in the comments above, it turns out to be how intellisense handles if blocks.
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 theif
, so after theif
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 potentialif
(or other scoping) statement.
Noting above, Failure's answer doesn't actually do much harm, other than hiding all intellisense error, which would be known anyway at build time.
Reference: http://youku.io/questions/324366/asp-net-mvc-error-name-o-is-not-declared https://msdn.microsoft.com/en-us/library/t8zbaa6f.aspx