[英]The type or namespace name does not exist in the namespace (are you missing an assembly reference?)
I know that this question has been already asked, but I cannot find anything that can help solve my problem.我知道已经有人问过这个问题,但我找不到任何可以帮助解决我的问题的东西。
I want to connect my aspx
page ( Retete.aspx
) to a Microsoft SQL database.我想将我的
aspx
页面 ( Retete.aspx
) 连接到 Microsoft SQL 数据库。 I'm getting this error on Retete.aspx.cs
:我在
Retete.aspx.cs
上收到此错误:
Error 1 The type or namespace name 'GlobalClass' does not exist in the namespace 'ProiectSera' (are you missing an assembly reference?) The error points to this line of code:
错误 1 命名空间“ProiectSera”中不存在类型或命名空间名称“GlobalClass”(您是否缺少程序集引用?)错误指向以下代码行:
ProiectSera.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
Where ProiectSera
is the project name, GlobalClass
is the file where I make the operation on the db.其中
ProiectSera
是项目名称, GlobalClass
是我对数据库进行操作的文件。
My using statements are:我的使用语句是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProiectSera;
The Target Framework is set to .net-4.5 .目标框架设置为.net-4.5 。
What should I do to solve this error?我应该怎么做才能解决这个错误?
Update My GlobalClass.cs is:更新我的 GlobalClass.cs 是:
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.IO;
using ProiectSera;
using System.Data.Services;
namespace ProiectSera.App_Code
{
public static class GlobalClass
{
static public void Update(string _param1, string _param2)
{//function to update}
}
}
App_Code is a folder where GlobalClass.cs is. App_Code 是 GlobalClass.cs 所在的文件夹。 I tried and
我试过
ProiectSera.App_Code.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text); //
but I had the same error.但我有同样的错误。 And I put the GlobalClass.cs in the project's root.
我将 GlobalClass.cs 放在项目的根目录中。 I also removed the .App_Code from
namespace ProiectSera.App_Code
我也从删除.App_Code
namespace ProiectSera.App_Code
UPDATE1 My Retete.aspx.cs is UPDATE1我的 Retete.aspx.cs 是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProiectSera;
using ProiectSera.App_Code;
namespace ProiectSera
{
public partial class Retete : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
string intValRefTempSol;
string intValRefTempAer;
// intValRefTempSol = ValRefTempSol.Text;
// intValRefTempAer = ValRefTempAer.Text;
// ProiectSera.App_Code.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
}
}
}
Your GlobalClass
is in the namespace ProiectSera.App_Code
.您的
GlobalClass
位于命名空间ProiectSera.App_Code
。
So the class name is ProiectSera.App_Code.GlobalClass
所以类名是
ProiectSera.App_Code.GlobalClass
Make sure you don't have a ProiectSera
class in the ProiectSera
namespace also, otherwise if declaring using ProiectSera
on top, it'll try to use it (as a general rule, don't name any class the same as your namespace).确保在
ProiectSera
命名空间中也没有ProiectSera
类,否则如果在顶部声明using ProiectSera
,它会尝试使用它(作为一般规则,不要将任何类命名为与命名空间相同的名称)。
If that still doesn't work, you may want to try using the global
namespace:如果这仍然不起作用,您可能需要尝试使用
global
命名空间:
global::ProiectSera.GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
and see if that works: if it doesn't, and GlobalClass
is in the same project, then there's something else you haven't shown us看看这是否有效:如果无效,并且
GlobalClass
在同一个项目中,那么您还没有向我们展示其他内容
Update更新
The only other thing that comes to mind, if you are positive that both files are on the same project/assembly, is that GlobalClass.cs
is not being actually compiled.唯一想到的另一件事是,如果您确定两个文件都在同一个项目/程序
GlobalClass.cs
,则GlobalClass.cs
并未实际编译。 Make sure the Build Action
is set to Compile
(you can see the build action right clicking on the GlobalClass.cs
in the solution explorer and selecting Properties
).确保
Build Action
设置为Compile
(您可以在解决方案资源GlobalClass.cs
中右键单击GlobalClass.cs
并选择Properties
看到构建操作)。
If you are using VS.NET:如果您使用的是 VS.NET:
Ensure the following...确保以下...
using ProiectSera;
).using ProiectSera;
)。 Assuming that this is the correct namespace. Then, simply call this in your code, assuming that Update is a static method of GlobalClass.然后,只需在您的代码中调用它,假设 Update 是 GlobalClass 的静态方法。
GlobalClass.Update(ValRefTempSol.Text, ValRefTempAer.Text);
EDIT: given that you've now posted your GlobalClass code, you can see that the namespace for this class is ProiectSera.App_Code
;.编辑:鉴于您现在已经发布了 GlobalClass 代码,您可以看到此类的命名空间是
ProiectSera.App_Code
;。 So you need to have that as your using statement in the other class using ProiectSera.App_Code;
所以你需要在另一个类中
using ProiectSera.App_Code;
把它作为你的 using 语句using ProiectSera.App_Code;
. . And then call it via simply GlobalClass.Update, as mentioned above.
然后通过简单的 GlobalClass.Update 调用它,如上所述。
If you don't understand how namespacing works in C#, then I recommend you check this out ( https://msdn.microsoft.com/en-us/library/dfb3cx8s.aspx ).如果您不了解命名空间在 C# 中的工作原理,那么我建议您查看一下 ( https://msdn.microsoft.com/en-us/library/dfb3cx8s.aspx )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.