名称“__o”在当前上下文中不存在 [英] The name '__o' does not exist in the current context
问题描述
我刚刚安装了Visual Studio 2015并打开了我正在开发的asp .net项目。我收到许多错误(完全相同)如下:
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:
错误CS0103当前名称__o不存在上下文
Error CS0103 The name '__o' does not exist in the current context
实际上,我没有任何名为__o的变量,代码的工作方式类似于charm(错误无效)我是我不能看到当我的代码真的有一个错误,因为它在这个列表中的某个地方,我应该检查整个列表。
Well actually I don't have any variables named __o and the code works like a charm (error is invalid) but what bothers me is that I'm not able to see when my code really has a error as it goes somewhere in this list and I should check the whole list.
推荐答案
我发现如果我选择 Build Only 而不是 Build + IntelliSense 的错误(与intellisense相关)将会消失。
I found out that if I choose Build Only instead of Build + IntelliSense the errors (that are related to intellisense) will go away.
更新1:原因
Update 1: The Reason
发生这种情况的原因是这样的代码:
The reason that this is happening is that for codes like this:
<% if (true) { %>
<%=1%>
<% } %>
<%=2%>
为了在设计时在<%=%>块中提供智能感知,ASP.NET生成赋值给临时的__o变量和语言(VB或C#),然后提供变量的智能感知。这在页面编译器看到第一个<%= ...%>块时完成。但是这里,块是在if里面,所以后如果关闭,变量超出范围。我们最终生成这样的东西:
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;
解决方法是在页面的早期添加一个虚表达式。例如。 <%=%>。这将不会呈现任何东西,并且它将确保在任何潜在的if(或其他范围界定)语句之前,在Render方法中将__o声明为顶级。
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.
Update 2:摆脱此错误,而不会失去其他intelliSense错误
点击错误列表面板左上角的过滤器按钮, CS0103 ,其中包含错误代码:当前上下文中不存在__o名称,这些错误将不再显示,您仍然可以有其他IntelliSense错误和警告:
Click on the filter button on the top left corner of the error list panel and uncheck the CS0103 which the error code for the: The name '__o' does not exist in the current context and these errors will not be shown anymore and you can still have other intelliSense errors and warnings:
这篇关于名称“__o”在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!