ASP.Net 2.0 VB WebSite项目“类型'异常'未定义”

时间:2023-01-17 09:17:12

All of a sudden our VB ASP.Net 2.0 WebSite Project started complaining that Exception was not defined.

突然间,我们的VB ASP.Net 2.0 WebSite项目开始抱怨没有定义Exception。

I have discovered that if I add "Imports System" to the header, or explicitly use System.Exception that it works, but this error permeates a lot of other System descendants like the Data namespace, and the DateTime object. We have hundreds and hundreds of pages, so adding Imports System to all of them not only would be time consuming, but it seems like a band-aid fix to the problem.

我发现如果我在标题中添加“Imports System”,或者显式使用System.Exception它可以工作,但是这个错误会渗透到很多其他系统后代,比如Data命名空间和DateTime对象。我们有数百个页面,因此将Imports系统添加到所有页面不仅耗费时间,而且似乎是对该问题进行创可贴修复。

I have checked the Project->Property Pages->References, and the web.config file, and the assembly is imported into the project, it is just not being "Auto Imported" into the Class Files like it USUALLY is. Note this does not JUST affect CodeBehind, but All className.vb files.

我检查了Project-> Property Pages-> References和web.config文件,并将程序集导入到项目中,它只是没有被“自动导入”到类文件中,就像USUALLY一样。请注意,这不会影响CodeBehind,而是影响所有className.vb文件。

I would like to fix this problem, but more importantly would like to understand what could cause the System namespace to all of a sudden stop being auto imported. There is obviously some file change that caused this, as my co-worker started seeing the problem this morning after he did a Full-Get on the project.

我想解决这个问题,但更重要的是想了解什么可能导致系统命名空间突然停止自动导入。显然有一些文件更改导致了这一点,因为我的同事今天早上在完成项目的Full-Get之后就开始看到这个问题了。

MORE: The Web.Config file located in the Windows\Microsoft.Net...\Config\Web.Config file does have the , and System is added. Adding the tags, and adding System to the LOCAL web.config did nothing to mitigate the problem.

更多:位于Windows \ Microsoft.Net ... \ Config \ Web.Config文件中的Web.Config文件确实具有,并添加了系统。添加标签,并将系统添加到LOCAL web.config没有做任何事情来缓解这个问题。

Any help would be appreciated. First SO Question, so I hope I was descriptive enough.

任何帮助,将不胜感激。第一个SO问题,所以我希望我足够描述。

3 个解决方案

#1


Alter the Web.config file and add the namespaces you want under the <pages> tag in <system.web>:

更改Web.config文件并在 中的 标记下添加所需的命名空间:

<pages>
    <namespaces>
        <add namespace="System"/>
        <add namespace="System.Data"/>
        <add namespace="System.Web"/>
        <add namespace="System.Web.UI"/>
        <add namespace="System.Xml"/>
        <add namespace="System.Data.SqlClient"/>
        <add namespace="System.Collections.Generic"/>
    </namespaces>
</pages>

#2


Check you section in your web.config, does it contain ?

检查web.config中的部分,它是否包含?

If so it shouldn't be there if not, check the Framework/CONFIG folder under Microsoft.NET in the windows folder. In the section in the web.config in that folder there should be:-

如果是这样,如果不存在,请检查windows文件夹中Microsoft.NET下的Framework / CONFIG文件夹。在该文件夹中的web.config部分应该有: -

<add namespace="System">

I can't imagine why anyone would remove it though

我无法想象为什么有人会删除它

#3


You could check to see if mscorlib is being ignored in your project build settings.

您可以检查项目构建设置中是否忽略mscorlib。

Project -> YourProject Properties -> Build -> Advanced, then make sure that "Do not reference mscorlib.dll" is unchecked.

项目 - > YourProject属性 - >构建 - >高级,然后确保未选中“不引用mscorlib.dll”。

#1


Alter the Web.config file and add the namespaces you want under the <pages> tag in <system.web>:

更改Web.config文件并在 中的 标记下添加所需的命名空间:

<pages>
    <namespaces>
        <add namespace="System"/>
        <add namespace="System.Data"/>
        <add namespace="System.Web"/>
        <add namespace="System.Web.UI"/>
        <add namespace="System.Xml"/>
        <add namespace="System.Data.SqlClient"/>
        <add namespace="System.Collections.Generic"/>
    </namespaces>
</pages>

#2


Check you section in your web.config, does it contain ?

检查web.config中的部分,它是否包含?

If so it shouldn't be there if not, check the Framework/CONFIG folder under Microsoft.NET in the windows folder. In the section in the web.config in that folder there should be:-

如果是这样,如果不存在,请检查windows文件夹中Microsoft.NET下的Framework / CONFIG文件夹。在该文件夹中的web.config部分应该有: -

<add namespace="System">

I can't imagine why anyone would remove it though

我无法想象为什么有人会删除它

#3


You could check to see if mscorlib is being ignored in your project build settings.

您可以检查项目构建设置中是否忽略mscorlib。

Project -> YourProject Properties -> Build -> Advanced, then make sure that "Do not reference mscorlib.dll" is unchecked.

项目 - > YourProject属性 - >构建 - >高级,然后确保未选中“不引用mscorlib.dll”。