我的代码中编译错误的原因是什么
本文关键字:是什么 错误 代码 编译 我的 | 更新日期: 2023-09-27 18:35:28
我在VS2010中运行 asp.net C#4.0应用程序。我收到以下编译错误:
Server Error in '/' Application.
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: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
Source Error:
Line 1: using System;
Line 2: using System.Collections.Generic;
Line 3: using System.Linq;
我的页面属性是:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
EnableEventValidation="false" Inherits="jsPlumb_jsPlumb_Default2" %>
我的 C#代码隐藏类:
namespace CompanyDisplay.jsPlumb.jsPlumb.jsPlumb
{
public class jsPlumb_jsPlumb_Default2 : System.Web.UI.Page
{
}
}
我希望命名空间用于运行一些 Web 服务应用程序。
尝试这样做:
-
在应用程序 web.config 文件的编译标记中添加 batch="false",如下所示
编译调试="真" 批处理="假"
-
清洁解决方案
-
删除Visual Studio中的临时文件文件夹(它在异常中显示的文件夹)
-
执行 IISRESET 并再次重建我的代码
我得到了答案;我应该将继承属性作为;
继承="CompanyDisplay.jsPlumb.jsPlumb.jsPlumb.jsPlumb_jsPlumb_Default2"
当代码隐藏类名与 aspx 页上的"inherits"属性不匹配时,会出现此错误。也许您尝试重命名某些内容?
此外,当您尝试查看新页面但没有编译源代码时,我看到了此错误,因此即使您的 aspx 存在,它也无法对抗相应的代码隐藏类。
编辑:
您的命名约定完全混乱,因此在正确匹配类名时遇到麻烦也就不足为奇了。
对不起,但这太荒谬了!
inherits="CompanyDisplay.jsPlumb.jsPlumb.jsPlumb.jsPlumb_jsPlumb_Default2"
修复您的约定,也许您会发现自己拥有这样的源文件:
CodeBehind="Default.aspx.cs" Inherits="MyNamespace.jsPlumb.Default"
不要像jsPlumb.jsPlumb.jsPlumb.jsPlumb那样做。那简直就是一场噩梦!