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...]

Recent Tweets

Twitter June 19, 21:25
终于开通了,以后更方便了😊【郑渝高铁将实现全线贯通运营,北京至重庆最快6小时46分可达】 https://t.co/Vwv5lg55rm https://t.co/GwnVhC3G2m

Twitter May 4, 23:00
因为疫情,五一只能在周边爬山,天气不错 https://t.co/ZJxRHj6fux

Twitter April 17, 22:20
坡峰岭爬山 https://t.co/gevMr3dkop

Twitter March 26, 23:21
月球陨落,剧情不错,特效牛逼 https://t.co/cyoCCXzVFu

Twitter February 1, 00:19
虎年快乐! https://t.co/Dltr5IMfcn

Twitter January 1, 00:05
Happy new year 2022! https://t.co/dCUV2yhO3K

Twitter December 26, 18:18
圣诞节🎄环球城市大道看电影,国产动画《雄狮少年》还是不错的 https://t.co/yVI76EZUVC

Twitter December 24, 22:06
圣诞快乐 https://t.co/SX3QadYBHY


Follow me on twitter >>

Month List