简体   繁体   English

命名空间中不存在类型或命名空间名称(您是否缺少程序集引用?)

[英]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 .目标框架设置为

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:

  1. Right click on the References folder on your project.右键单击项目上的 References 文件夹。
  2. Select Add Reference.选择添加引用。
  3. Select the .NET tab (or select the Browse button if it is not a .NET Framework assembly).选择 .NET 选项卡(如果不是 .NET Framework 程序集,则选择浏览按钮)。
  4. Double-click the assembly containing the namespace in the error message.双击错误消息中包含命名空间的程序集。
  5. Press the OK button.按确定按钮。

Ensure the following...确保以下...

  • That you have a project reference to ProiectSera from your web application, if it's in a separate library.如果您的 Web 应用程序位于单独的库中,则您有对 ProiectSera 的项目引用。 If GlobalClass is in the web application project itself, you won't require this, but if GlobalClass is defined in a separate library in the same solution or elsewhere, then you're going to need to add a reference to that external library in your web application.如果 GlobalClass 在 Web 应用程序项目本身中,则不需要这样做,但如果 GlobalClass 是在同一解决方案或其他地方的单独库中定义的,那么您将需要在您的项目中添加对该外部库的引用Web应用程序。
  • Ensure that ProiectSera should not be ProjectSera (if it's a typo).确保 ProiectSera 不应该是 ProjectSera(如果它是一个错字)。
  • Ensure that you have your ProiectSera using statement in place at the top ( using ProiectSera; ).确保您的 ProiectSera using 语句位于顶部( using ProiectSera; )。 Assuming that this is the correct namespace.假设这是正确的命名空间。 Check the namespace of your GlobalClass class and use that using accordingly in the class that wishes to use its functionality.检查 GlobalClass 类的命名空间,并在希望使用其功能的类中相应地使用它。
  • 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.

相关问题 类型或名称空间名称在名称空间中不存在“是否缺少程序集引用?” - The type or namespace name does not exist in the namespace ''are you missing an assembly reference ?" 命名空间中不存在类型或命名空间名称(是否缺少程序集引用?)- 无法引用 class - The type or namespace name does not exist in the namespace (are you missing an assembly reference?) - Can't reference a class CS0234:命名空间“<namespace1>”中不存在类型或命名空间名称“<namespace2>”。 (你错过了一个程序集引用吗?) - CS0234: The type or namespace name '<namespace2>' does not exist in the namespace '<namespace1>.' (are you missing an assembly reference?) 错误 CS0234:命名空间“Microsoft”中不存在类型或命名空间名称“Azure”(您是否缺少程序集引用?) - error CS0234: The type or namespace name 'Azure' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) 命名空间“System.Web”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?)Kentico - The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) Kentico 命名空间“Microsoft.SqlServer”中不存在类型或命名空间名称“Smo”(您是否缺少程序集引用?) - The type or namespace name 'Smo' does not exist in the namespace 'Microsoft.SqlServer' (are you missing an assembly reference?) 命名空间“MicrosoftSqlServer”中不存在类型或命名空间名称“Management”,您是否缺少程序集引用 - the type or namespace name 'Management' does not exist in the namespace 'MicrosoftSqlServer' are you missing an assembly reference CS0234 C#类型或名称空间名称&#39;Slydeextender&#39;在名称空间中不存在(您是否缺少程序集引用?) - CS0234 C# The type or namespace name 'Slydeextender' does not exist in the namespace (are you missing an assembly reference?) 命名空间“Android.Support.V4.App”中不存在类型或命名空间名称“TaskStackBuilder”(您是否缺少程序集引用?) - The type or namespace name 'TaskStackBuilder' does not exist in the namespace 'Android.Support.V4.App' (are you missing an assembly reference?) 命名空间“Microsoft.AspNetCore”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?) - The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM