找不到类型或命名空间(网站)
我创建了一个 ASP.NET Web 应用程序项目,它现在可以正常构建和工作。 但是,我正在尝试将此项目添加到我的网站。 因此,我所做的就是从 VS 创建一个新网站,然后将 Web 应用程序项目中的所有 .CS 文件添加到该网站。
即使 Web 应用程序项目构建成功,当我在网站中使用相同的代码并构建它时,我收到错误:
类型或命名空间名称 找不到“ADONET_命名空间” (您是否缺少用户指令或 程序集参考?)
这是我的 master.cs 文件的顶部:
using System;
using System.Collections.Generic;
using System.Collections;
namespace AddFileToSQL
{
public partial class _Default : System.Web.UI.Page
{
和我的 ADONET_methods.cs 文件的顶部:
using System;
using System.Collections;
using System.Data;
namespace ADONET_namespace
{
public class ADONET_methods : System.Web.UI.WebControls
{
最后是我的子类的顶部:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ADONET_namespace;
namespace AddFileToSQL
{
public partial class DataMatch : _Default
{
在这个子类文件中,ADONET_namespace 下有一条波浪线并悬停超过它会返回上面指定的错误。 我将此 ADONET_methods.cs 文件以与我在 Web 应用程序项目中相同的文件结构格式存储在该网站上。 那么,如果它在该项目中成功构建,为什么在这个网站中不能成功构建呢?
我在 Stack Overflow 上搜索了类似的问题,发现一个问题与我提出了同样的问题,但我尝试了那里列出的所有解决方案。 我也用谷歌搜索了这个问题并尝试了所有的建议,但它们都不起作用。 我已将此 ADONET_methods.cs 文件添加到此网站内的不同位置,以测试是否找到它,例如在 App_Data 文件夹、References 文件夹下,以及与其他 .CS 文件处于同一级别(例如位于 Web 应用程序项目中)。
我还能尝试什么? 这段代码是顺便在 VS 2008 中用 C# 编写的,在带有 IIS6 Manager 的 XP Pro 上运行。
I created an ASP.NET Web App project and it builds and works correctly now. However, I am trying to add this project to my website. So what I've done is I create a new Web Site from VS and then I added all of the .CS files from my Web App project to this Web Site.
Even though the Web App project builds successfully, when I use this same code in my Web Site and I build it, I get the error:
The type or namespacae name
'ADONET_namespace' could not be found
(are you missing a user directive or
an assembly reference?)
Here is the top part of my master.cs file:
using System;
using System.Collections.Generic;
using System.Collections;
namespace AddFileToSQL
{
public partial class _Default : System.Web.UI.Page
{
And the top of my ADONET_methods.cs file:
using System;
using System.Collections;
using System.Data;
namespace ADONET_namespace
{
public class ADONET_methods : System.Web.UI.WebControls
{
Finally the top of my child class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ADONET_namespace;
namespace AddFileToSQL
{
public partial class DataMatch : _Default
{
In this child class file, there is a squiggly line under ADONET_namespace and hovering over it returns the error specified above. I have this ADONET_methods.cs file stored in same file structure format on this Web Site as I do on my Web App project. So if it builds successfully in that project, why not in this Web Site?
I have searched Stack Overflow for similar questions and I found one question which was asking the same thing as me, but I tried all of the solutions listed there. I also googled this problem and tried all of the suggestions, but none of them worked either. And I have added this ADONET_methods.cs file to different locations within this Web Site to test out if it was being found or not, like under App_Data folder, References folder, and also in the same level as the other .CS files (like it is in the Web App project).
What else can I try? This code is written in C# by the way in VS 2008, running on an XP Pro with IIS6 Manager.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将其放入您的 App_Code 目录中。
Try putting it in your App_Code directory.
不确定这是否会导致任何问题,但您是否希望将
ADONET_methods.cs
文件中的类命名为ADONET_namespace
? 类和命名空间具有相同的名称似乎很奇怪。Not sure if this is causing any issues, but do you want your class in the
ADONET_methods.cs
file to be namedADONET_namespace
? It seems odd to have both the class and the namespace with the same name.对于 App_Code 文件夹中的每个代码(例如:.cs)文件,确保“构建操作”属性设置为“编译”而不是“内容”或其他任何值。
For each code -- example: .cs -- file in the App_Code folder, ensure that the Build Action property is set to "Compile" and not "Content" or anything else.