导致错误的 ASP.NET 页面指令

xel*_*o52 5 c# visual-studio-2010 visual-studio-2008

我有一个页面表现出最奇怪的行为。在构建/调试我的项目时,我有时会收到指向我的页面指令的构建错误。

如果我在指令中的任何两个属性之间插入一个额外的空格,错误就会消失并且构建成功。

页面指​​令:

<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="myPage.aspx.cs" Inherits="com.mycompany.UserControls.myPage" %>
Run Code Online (Sandbox Code Playgroud)

导致的错误:

Keyword, identifier, or string expected after verbatim specifier: @ C:\mypath\myPage.aspx   1   1   myProjectName

A namespace cannot directly contain members such as fields or methods   C:\mypath\myPage.aspx   1   1   myProjectName
Run Code Online (Sandbox Code Playgroud)

重申一下,例如,在错误之间添加额外的空格PageLanguage="C#"暂时清除错误。我会在下一次构建时看到 100% 的成功率,但错误最终会再次出现。我经常可以通过关闭显示myPage.aspx和构建/重建我的项目的编辑器来强制错误。

注意:此行为出现在 Visual Studio 2008 中,并且在切换到 Visual Studio 2010 后仍然存在。

编辑:更正@了有问题的页面指令中省略的错字。

有任何想法吗?

Ric*_*fen 4

您是否缺少开头 <% 和 Page 关键字之间的 @ 符号?你有

<% Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="myPage.aspx.cs" Inherits="com.mycompany.UserControls.myPage" %>
Run Code Online (Sandbox Code Playgroud)

应该是

<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="true" CodeBehind="myPage.aspx.cs" Inherits="com.mycompany.UserControls.myPage" %>
Run Code Online (Sandbox Code Playgroud)