ASP.NET 如何解决页面上的 CS1513: } 预期错误

发布于 2025-01-07 21:26:16 字数 676 浏览 5 评论 0原文

在浏览器中查看 ASP.NET 页面时,我在运行时收到错误。我没有收到任何构建错误,但在运行时收到以下编译器错误:

编译错误

描述:编译服务此请求所需的资源期间发生错误。请查看以下具体错误详细信息并适当修改您的源代码。

Compiler Error Message: CS1513: } expected

Source Error:


Line 329:            #line hidden
Line 330:            __output.Write("\r\n\t\t\t</div>\r\n\t\t");
Line 331:        }
Line 332:        
Line 333:        private System.Web.UI.Control __BuildControl__control7() {

Source File: c:\Windows\Microsoft.NET\Framework\v1.1.4322\
    Temporary ASP.NET Files\xxxxxxxx\450ffa78\d46d847d\
    k1gsz9dj.0.cs    Line: 331 

我无法在源代码中找到任何缺失的 },并且此错误发生在临时 ASP.NET 文件目录中存在的生成代码文件中。如何追踪到我的页面或页面上的用户控件中实际格式错误的代码行?

I am getting an error at run time when viewing my ASP.NET page in the browser. I am not getting any build errors however I am getting the following compiler error at runtime:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1513: } expected

Source Error:


Line 329:            #line hidden
Line 330:            __output.Write("\r\n\t\t\t</div>\r\n\t\t");
Line 331:        }
Line 332:        
Line 333:        private System.Web.UI.Control __BuildControl__control7() {

Source File: c:\Windows\Microsoft.NET\Framework\v1.1.4322\
    Temporary ASP.NET Files\xxxxxxxx\450ffa78\d46d847d\
    k1gsz9dj.0.cs    Line: 331 

I cannot locate any missing } in my source code and this error is occurring in the generated code files that exist in the Temporary ASP.NET Files directory. How can I trace this to the line of code that is actually malformed in my page or user controls on my page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夏了南城 2025-01-14 21:26:16

如果错误代码如下:

变量名与保留字相同,则可以重命名变量。

代码段,例如:

@model MyModel
{
    var appname = @Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp);
}

删除 Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp) 之前的“@”

代码段或节用法,例如:

@section{ 
    <!-- hiiii it's not about an error -->
}

删除撇号来自部分评论。

如果不是这些特定情况,您可以尝试通过应用源归约来查找生成错误的位置。删除/剪切/注释掉代码片段,直到您可以可靠地关闭和打开错误。如果不是上述情况之一,则引发错误的代码可能是罪魁祸首。

If the error code related as following:

A variable name same as reserved word then you can rename variable.

A code segment such as:

@model MyModel
{
    var appname = @Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp);
}

Remove '@' coming before Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp)

A code segment or section usage such as:

@section{ 
    <!-- hiiii it's not about an error -->
}

Remove the apostrophe from comment in section.

If it is none of these specific cases you can attempt to locate where the error is generated by applying a source reduction. Delete/cut/comment out pieces of code until you can reliably turn the error off and on. The code that turns the error on is likely the culprit if it is not one of the above situations.

初相遇 2025-01-14 21:26:16

在标记(aspx 或 ascx)中查找类似以下的块:

<% ... some C# code.... { %>

   markup(controls, html etc)

<% } %>

任何打开的括号 { 都需要用另一个括号 } 关闭。

这些页面或控件在首次请求时由 ASP .Net 编译一次。
Visual Studio 不编译 aspx 或 ascx 文件。

如果项目是“网站”类型,Visual Studio 会编译 aspx/ascx 文件,但如果项目是“Web 应用程序”类型,Visual Studio 不会“编译”标记(它不会生成与 aspx/ascx 标记相对应的类)

Look in the markup (aspx or ascx) for blocks like:

<% ... some C# code.... { %>

   markup(controls, html etc)

<% } %>

Any opened bracket { needs to be closed with another bracket }.

These pages or controls are compiled once by ASP .Net when they are first requested.
Visual Studio doesn't compile aspx or ascx files.

If the project is "Web Site" type, Visual Studio compiles the aspx/ascx files, but if the project is "Web Application" type Visual Studio doesn't "compile" the markup (it does not generate the corresponding classes to the aspx/ascx markup)

恬淡成诗 2025-01-14 21:26:16

在我的网站上,问题是由如下代码块引起的:

            @{  
                var currentNode = @linkedList.Find(@CurrentPage);
                if (@currentNode.Next != null)
                {
                    var next = @currentNode.Next;
                    <li>
                        @next.Name
                    </li>
                }
                if (@currentNode.Previous != null)
                {
                    var prev = @currentNode.Previous;
                    <li>
                        @prev.Name
                    </li>
                }
            }

我不确定为什么问题是由嵌套引起的。这可能是编译器中的一个错误。

On my site, the problem was caused by a block of code that looked like this:

            @{  
                var currentNode = @linkedList.Find(@CurrentPage);
                if (@currentNode.Next != null)
                {
                    var next = @currentNode.Next;
                    <li>
                        @next.Name
                    </li>
                }
                if (@currentNode.Previous != null)
                {
                    var prev = @currentNode.Previous;
                    <li>
                        @prev.Name
                    </li>
                }
            }

I'm not sure why the problem was caused by the nesting. This may be a bug in the compiler.

深巷少女 2025-01-14 21:26:16

我遇到了类似的问题,只有在经过反复试验后才能找到它。

我犯的错误是在 foreach 循环内的变量中添加一个“@”,该循环以以下内容开头:

@foreach

I got a similar problem and oculd find it only after a log of trial and error.

The error I made was to add a '@' to variables inside a foreach loop which started with:

@foreach
初见你 2025-01-14 21:26:16

正如错误所示,您缺少右大括号 '}'

查看 msdn 编译器错误文档:

如 MSDN 上的示例所示:

// the below will cause CS1513 since namespace is missing '}'
namespace y    
{
   class x
   {
      public static void Main()
      {
      }
   }

Well as the error suggests, you are missing a closing curly brace '}'

Have a look at the msdn compiler errors documentation:

As in the example on MSDN:

// the below will cause CS1513 since namespace is missing '}'
namespace y    
{
   class x
   {
      public static void Main()
      {
      }
   }
萌面超妹 2025-01-14 21:26:16

尝试在 Visual Studio 中编译它。我认为它还会显示具有不完整花括号的代码的确切行。

编译错误cs1513

try to compile it in visual studio. i think it will also show where the exact line of the code that has incomplete curly braces.

compilation error cs1513

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文