ASP.NET 如何解决页面上的 CS1513: } 预期错误
在浏览器中查看 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果错误代码如下:
变量名与保留字相同,则可以重命名变量。
代码段,例如:
删除
Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp)
之前的“@”代码段或节用法,例如:
删除撇号来自部分评论。
如果不是这些特定情况,您可以尝试通过应用源归约来查找生成错误的位置。删除/剪切/注释掉代码片段,直到您可以可靠地关闭和打开错误。如果不是上述情况之一,则引发错误的代码可能是罪魁祸首。
If the error code related as following:
A variable name same as reserved word then you can rename variable.
A code segment such as:
Remove '@' coming before
Model.Apps.FirstOrDefault(x => x.ID == Model.SelectedApp)
A code segment or section usage such as:
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.
在标记(aspx 或 ascx)中查找类似以下的块:
任何打开的括号
{
都需要用另一个括号}
关闭。这些页面或控件在首次请求时由 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:
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 compileaspx 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 theaspx/ascx
markup)在我的网站上,问题是由如下代码块引起的:
我不确定为什么问题是由嵌套引起的。这可能是编译器中的一个错误。
On my site, the problem was caused by a block of code that looked like this:
I'm not sure why the problem was caused by the nesting. This may be a bug in the compiler.
我遇到了类似的问题,只有在经过反复试验后才能找到它。
我犯的错误是在 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:
正如错误所示,您缺少右大括号 '}'
查看 msdn 编译器错误文档:
如 MSDN 上的示例所示:
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:
尝试在 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