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

查看:34
本文介绍了当前上下文中不存在名称“__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 an 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:原因

发生这种情况的原因是对于这样的代码:

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

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

为了在设计时在 <%= %> 块中提供智能感知,ASP.NET 生成对临时 __o 变量和语言(VB 或 C#)的赋值,然后为变量提供智能感知.这是在页面编译器看到第一个 <%= ... %> 块时完成的.但是在这里,块在 if 内,所以在 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;

解决方法是在页面的早期添加一个虚拟表达式.例如

The workaround is to add a dummy expression early in the page. E.g.

<%=""%>

这不会渲染任何东西,它会确保在任何潜在的 if(或其他范围)语句之前,__o 在 Render 方法中被声明为顶级.

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:在不丢失其他 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屋!

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