The base class includes the field 'xxx', but its type is not compatible with the type of control

by shinichi_wtn 2010-04-11 14:15

今天在编译ASP.NET项目的时候突然出现The base class includes the field 'WebUserControl1', but its type (common_WebUserControl) is not compatible with the type of control (ASP.common_webusercontrol_ascx) 的错误信息,上网搜索了一下,有两种可能的原因:

一个是类不能循环引用,否则会发生编译错误,重新组织文件夹和文件,修改有循环引用的地方(我没有遇到这种情况);

一个是在定义UserControl的时候,直接复制粘贴了曾经的代码,传统模式时,UserControl第一行声明应该是

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl1.ascx.cs" Inherits="HighwayShanxiWeb.WebUserControl1" %>

而在编译模式下,CodeFile不再起作用,毕竟最后所有类都被打包成程序集,因此这里要把CodeFile属性替换为CodeBehind属性,即修改成如下代码即可

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="HighwayShanxiWeb.WebUserControl1" %>

Comments (1) -

eoo
6/28/2011 3:44:41 PM #

改成CodeBehind之后,运行出现 Error  279  Could not load type 'WebUserControl'.  的错误阿

Reply

(仅用于Gavatar)

  Country flag

biuquote
  • Comment
  • Preview
Loading

About

shinichi_wtnI'm Shinichi_wtn

Software Engineering Manager at Microsoft

[More...]


Month List