简体   繁体   English

在生成过程中出现错误“找不到类型或名称空间名称”

[英]Error “The type or namespace name could not be found” during a build process

I'm using in C# Windows Application, I have using 我在C#Windows应用程序中使用,我在使用

TempProWin --> For Windows Application Projects TempProWin->对于Windows应用程序项目
TempProApp --> For Database and functionality like Class File using CSLA Method. TempProApp->用于使用CSLA方法的数据库和类文件之类的功能。

In TempProWin.frmLogin.cs: 在TempProWin.frmLogin.cs中:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using  TempProApp;

private void frmLogin_Load(object sender, EventArgs e)
{
 UserLoginList oUserLoginList = UserLoginList.GetUserLoginList();
 cmbUserName.DataSource = oUserLoginList;
 cmbUserName.DisplayMember = "Select User";
}

But When I build this application, I got the following error: 但是,在构建此应用程序时,出现以下错误:

Error 5 The type or namespace name 'TempProApp' could not be found (are you missing a using directive or an assembly reference?) 错误5找不到类型或名称空间名称'TempProApp'(您是否缺少using指令或程序集引用?)

I already include reference of TempProApp.dll from the path of D:\\TempPro\\TempProApp\\bin\\Debug 我已经从D:\\ TempPro \\ TempProApp \\ bin \\ Debug的路径中包含TempProApp.dll的引用

RightClick on TempProApp and Go to definition. 右键单击TempProApp并转到定义。

On the top most, you will see the dll name and its version. 在最顶部,您将看到dll名称及其版本。 You can verify that whether you are using the same dll version or not. 您可以验证是否使用相同的dll版本。

A spurious “The type or namespace name could not be found” build error can result if you have other build warnings. 可能导致虚假的 “类型或命名空间名称无法找到”生成错误,如果你有其他构建警告。

I'd partially coded an asynch HTTP method, which was generating warnings about missing awaits. 我对异步HTTP方法进行了部分编码,该方法正在生成有关等待丢失的警告。 I planned to get the rest of the system building, then fix that. 我计划进行其余的系统构建,然后修复该问题。

But I started getting the above hard error. 但是我开始遇到上述困难错误。 I've spent the last three hours trying to isolate its cause. 我花了最后三个小时试图找出原因。 I tried all the suggested fixes, quadruple checked names, etc., and even deleted and recreated the project that was generating the complaints. 我尝试了所有建议的修补程序,四重选中的名称等,甚至删除并重新创建了引起投诉的项目。 No change. 没变。 It seemed strange to me that when I clicked Go To Definition on the offending type reference, VS 2012 could find it with no problem. 当我在令人反感的类型引用上单击“转到定义”时,VS 2012可以毫无问题地找到它。 WTF* WTF *

As a last resort, I commented out the code that was producing the warnings. 作为最后的选择,我注释掉了生成警告的代码。 This fixed the spurious error messages and the build succeeded. 这修复了错误的错误消息,并且构建成功。

So, if you've ruled out the other causes and you have other build warnings , try fixing those. 因此,如果您已排除其他原因,并且还有其他构建警告 ,请尝试解决这些问题。

Be sure you have spelled correctly the namespace you want to include. 确保正确拼写了要包括的名称空间。 Also the .dll referenced must have been successfully build. 而且,所引用的.dll也必须已成功构建。

One way to be always sure for both the above is to include the project you want to reference in your working project. 始终确保上述两项的一种方法是将要引用的项目包括在工作项目中。 This will also ensure that in every build of your working Project the referenced PROJECT re-builds too, so any changes made will take affect 这也将确保在您的工作项目的每个构建中,引用的PROJECT也会重新构建,因此所做的任何更改都会生效。

On Solution Explorer->Right Click-> Add existing Project-> Select the Project you would initially Reference

On References->Add new Reference-> Select Projects Tab-> Select the Project you added

If the namespace you are using does not expose any public methods it can also cause this error. 如果您使用的名称空间未公开任何公共方法,则也可能导致此错误。 Confirm that the namespace you are using contains public methods in a public class. 确认您使用的名称空间在公共类中包含公共方法。

I was facing teh same error while attaching Gamecenter Achievements, then i realized that i missed a classname. 附加Gamecenter Achievements时遇到相同的错误,然后我意识到我错过了一个类名。

using UnityEngine.SocialPlatforms;
using UnityEngine.SocialPlatforms.GameCenter;

maybe you are missing 1 classname too. 也许您也缺少1个类名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM