名称为“__o'不存在于当前上下文存在 [英] The name '__o' does not exist in the current context

查看:2057
本文介绍了名称为“__o'不存在于当前上下文存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚安装了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和代码工作就像一个魅力(错误是无效的),但什么麻烦事了我的是,我无法看到,因为它去的地方在此列表中,我应该检查整个列表时,我的代码真的有一个错误。

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.

推荐答案

我发现,如果我选择的只建而不是构建+智能感知的错误(涉及智能感知)会自行消失。

I found out that if I choose Build Only instead of Build + IntelliSense the errors (that are related to intellisense) will go away.

更新1:原因

这是发生这种情况的原因是,像这样的代码:

The reason that this is happening is that for codes like this:

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

在以上述<提供智能感知;%=%>在设计时块,ASP.NET生成分配到一个临时变量__o和语言(VB或C#),然后提供该变量的智能感知。 %= ...%>块;当页面编译器看到的第一个<做到这一点。但在这里,块内,如果,所以以后如果关闭,该变量超出范围。我们最终会产生这样的:

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;



解决方法是在网页中添加早期的虚拟表达。例如。 <%=%>。这不会呈现任何东西,它会确保__o声明中Render方法顶尖水平,如果有可能的(或其他作用域)语句之前。

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.

更新2:摆脱这种错误而不失去其他智能感知错误

点击过滤器上的按钮上的错误列表面板,并取消选中的左上角在 CS0103 这对于错误代码:名称'__o'不在当前情况下存在并这些错误不会再显示,你还可以有其他的智能感知错误和警告:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆