Parser Error 报错解决

很奇怪,这个问题居然没有找到中文的解决方法,但用google找到的答案却是五花八门。

碰到这个问题很蹊跷,将编译生成好的系统挪到服务器间,只有一个页面报错,其它页面不报错,而在本地测试却没有错误。超初以为是服务器相关配置问题,但考虑了一下排除了这方面的原因---所有的页面都OK,就一个页面不OK,报错如下:

Parser Error: The base class includes the field 'XXX', but its type is not compatible

不知有没其它网友碰到过这个问题。
找到很多解决办法,老实说试了一下都不是行,我是来了一个很绝的了,由于我的用户控件名跟页面名称是一样的,都是QSSList,只是一个是QSSList.ascx,一个是QSSList.aspx,看了很长时间,我还是把其中一个名字改成另外的,当然切记:当你改完名称时,一定要将CodeBehind中的相关名称也要改过来,要不就会报错,编译不成功了。,当然,也许我这个是土办法,但这个应该是最简单最实效的,老外们为这个问题讨论了很多解决方法,我收集如下:方便大家参考一下

一般的报错代码如下

Configuration Error

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

Parser Error Message: The base class includes the field ‘XXX’, but its type (‘YYY’) is not compatible with the type of control (‘ZZZ’).

You are running a different version of the .NET Framework than the one for which your application was generated.



解决方案:

来源于:
http://www.ironspeed.com/Designer/3.2.1/WebHelp/Part_VI/Parser_Error_The_base_class_includes_the_field_XXX_but_its.htm

这里主要是说配置的原因,不过我个人认为这个solution不大可能使用,因为一般能运行系统的,大多数IIS是OK的:

Microsoft IIS is Not Installed on Your Machine (服务器上没有装IIS)

Microsoft IIS is Stopped (Not Running) (你的IIS停止了)

Running Microsoft IIS 6.0 on Windows Server 2003 (在win2003Server中运行了IIS6.0)

You are running a different version of the .NET Framework than the one for which your application was generated.  Configure the Microsoft IIS server to use .NET Framework version 1.1 and the application should then run properly.

在一台机子上运行了不同版本的Net.Framework,这个原因值得注意.


我解决这个问题的“灵感”主要来源于这个贴子:
http://forums.asp.net/p/960707/1641916.aspx

其解决方案归纳得很好:

1. If you spend more than 5 minutes on a quirky problem like this in ASP.NET web projects, manually clean the build. You may need to turn off your web server and dump the files in your temporary ASP.NET folder for the site. E.g. Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\My site

清除你的project,重新建立一个新的project,把文件重新在Net2.0状况下编译生成

2.To get controls to work nicely and easily in web application projects and web site projects, use them the expected "VS 2005 way". You only need to do this if you are having a problem - you don't need to update all 1000 pages in your monster site. The following apply both to the controls and the pages you put them on.

Use <%@page CodeBehind="x" %>, not <%@page CodeFile="x" %> (see previous post by Maduka ).  
Make sure your controls and pages has a designer (webform.aspx.designer.cs) file. This ensures correct declaration, and is respected by run-time compilation in a way that declarations of controls in your own page are not. Web site projects do not appear to need the designer file.  
Make sure all your pages and controls are declared as "partial" classes, even if you don't have the aspx.designer.cs class present.


确认你所使用的用户控件和自定义控件在整个project中运行良好,确保你所有的aspx页面都有相对应的aspx.cs文件,同时确认在你的design中均有对cs相关的声明,确认你所有的页面和控件都运用了partial类来实现继承(这主要其实是在page_load这里)
例如:
public partial class RMS_QSScoreList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void QSSList1_Load(object sender, EventArgs e)
    {

    }
}


其实出现这个问题的原因大多数是因为asp.net自己产生的临时文件所致,所以不能忽视编译过程中一些相关的warnings,因为可能有一些warning可能对你project的编译成功没影响,但是对你局部的一些小地方却带来很难发现原因的错误。这也是提醒我们在编译时要注意的一个地方了。不过看到相关资料,据说这是一个asp.net2.0的一个Bug,哈哈,俺也碰到了bug.

请大家多多指教!相互交流.[em16]




上一篇: 没有钱,你能做什么?
下一篇: Access导入SQL2005
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 33084
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 30 字 | UBB代码 关闭 | [img]标签 关闭