我的一个WEB项目正常运行了一个多月。昨天晚上突然客户那边说报了一个错误(心里那个郁闷呀)然后我调试看了一下。
是一个用户控件错误 CS0246: 找不到类型或命名空间名称“XXX”(是否缺少 using 指令或程序集引用?)我心一凉,想丫的,总算出问题了。记得刚刚做这个项目时,偶然发现用户控件很好使(以前没搞过.NET),就在网页里面加了两个,当时如果我在网站里其它页面随便改点东西,然后生成网站,都会提示“找不到类型或命名空间名称“XXX”(是否缺少 using 指令或程序集引用?”,可我再“重新生成网站”,那个问题就消失了。凭我应用程序开发的经验,我知道这个地方很有可能以后出大乱子。结果才一个月就出了。
请教高手这是怎么回事。BAIDU GOOGLE了半天,也有些人提出了类似的问题,可没一个得到真正的答案。问题解决,必开百分帖相送。

解决方案 »

  1.   

    有可能存在ls说的你可以重新编译一下整个解决方案,别只Build那个web项目
    说不定你的类库修改了,但引用的还是旧的类
      

  2.   

    出问题的时候,检查一下,看看ascx对应的.cs文件是否被排除在了项目外?
      

  3.   

    刚刚又认真的查了一下:所有文件都在。忘了说我是用动态加载的用户控件: UserWeb_EditTempDetail etd = (UserWeb_EditTempDetail)this.LoadControl("EditTempDetail.ascx");
     etd.WorkId = nWorkId;
     ...
    //错误 CS0246: 找不到类型或命名空间名称“UserWeb_EditTempDetail”(是否缺少 using 指令或程序集引用?)
      

  4.   


    Check the web.config file. In the <system.web><pages></pages></system.web>
    section, I had the following:<pages
    buffer="true"
    enableSessionState="true"
    enableViewState="true"
    enableViewStateMac="true"
    smartNavigation="false"
    autoEventWireup="true"
    pageBaseType="System.Web.UI.Page"
    userControlBaseType="System.Web.UI.UserControl"
    validateRequest="true"
    masterPageFile=""
    theme="CardinalHealthTheme"
    styleSheetTheme=""
    maxPageStateFieldLength="-1"
    compilationMode="Always"
    pageParserFilterType=""
    viewStateEncryptionMode="Auto"
    maintainScrollPositionOnPostBack="false"
    asyncTimeout="45">
    <namespaces>
    <clear />
    </namespaces>
    <tagMapping>
    <clear />
    </tagMapping>
    </pages>It caused the same error that you reported. If you notice, I cleared the
    namespaces and tagmappings. If you remove the <clear /> from the namespaces
    section, it will build again.
      

  5.   

    还有可能就是你用了两台服务器,两个上面的dll不一样。
      

  6.   

    还有就是用完整命名空间试验一下:完整命名空间.UserWeb_EditTempDetail etd = (完整命名空间.UserWeb_EditTempDetail)this.LoadControl("EditTempDetail.ascx");
     etd.WorkId = nWorkId;