找不到類型或命名空間名稱[重複]

本文翻譯自:The type or namespace name could not be found [duplicate]

I have a C# solution with several projects in Visual Studio 2010 . 我有一個C#解決方案,在Visual Studio 2010有幾個項目。 One is a test project (I'll call it " PrjTest "), the other is a Windows Forms Application project (I'll call it " PrjForm "). 一個是測試項目(我將其稱爲“ PrjTest ”),另一個是Windows Forms Application項目(我稱之爲“ PrjForm ”)。 There is also a third project referenced by PrjForm, which it is able to reference and use successfully. 還有一個由PrjForm引用的第三個項目,它能夠成功引用和使用。

PrjForm references PrjTest , and PrjForm has a class with a using statement: PrjForm引用PrjTestPrjForm有一個帶有using語句的類:

using PrjTest;
  1. Reference has been correctly added 參考已正確添加
  2. using statement is correctly in place using語句正確到位
  3. Spelling is correct 拼寫是正確的
  4. PrjTest builds successfully PrjTest構建成功
  5. PrjForm almost builds, but breaks on the using PrjTest; PrjForm幾乎構建,但打破了using PrjTest; line with the error: 與錯誤一致:

The type or namespace name 'PrjTest' could not be found (are you missing a using directive or an assembly reference?) 找不到類型或命名空間名稱'PrjTest'(您是否缺少using指令或程序集引用?)

I've tried the following to resolve this: 我嘗試過以下方法來解決這個問題:

  1. Removed Resharper (since Resharper had no trouble recognizing the referenced project, I thought it might be worth a shot) 刪除了Resharper(因爲Resharper在識別引用的項目時沒有遇到任何麻煩,我認爲它可能值得一試)
  2. Removed and re-added the reference and using statement 刪除並重新添加了引用和using語句
  3. Recreated PrjForm from scratch 從頭開始重新創建PrjForm
  4. PrjForm currently resides inside the PrjTest folder, I tried moving it to an outside folder PrjForm目前駐留在PrjTest文件夾中,我嘗試將其移動到外部文件夾
  5. Loaded the solution on a different computer with a fresh copy of VS 2010 使用VS 2010的新副本在另一臺計算機上加載解決方案

I have done my homework and spent far too long looking for an answer online, none of the solutions has helped yet. 我做完了我的功課,花了很長時間在線尋找答案,但沒有一個解決方案有幫助。

What else could I try? 我還能嘗試什麼?


#1樓

參考:https://stackoom.com/question/JzaU/找不到類型或命名空間名稱-重複


#2樓

just changed Application's target framework to ".Net Framework 4". 剛剛將Application的目標框架更改爲“.Net Framework 4”。

And error got Disappeared. 錯誤消失了。

good luck; 祝好運; :D :d


#3樓

I had the same issue. 我遇到過同樣的問題。 The target frameworks were fine for me. 目標框架對我來說很好。 Still it was not working. 它仍然無法正常工作。 I installed VS2010 sp1, and did a "Rebuild" on the PrjTest. 我安裝了VS2010 sp1,並在PrjTest上進行了“Rebuild”。 Then it started working for me. 然後它開始爲我工作。


#4樓

Changing the framework to 將框架更改爲

.NET Framework 4 Client Profile

did the job for me. 爲我做了這份工作。


#5樓

For COM/ActiveX references, VS 2012 will show this error right on using statement. 對於COM / ActiveX引用,VS 2012將在using語句上顯示此錯誤。 Which is quite funny, since it's saying that may be you are missing a using statement. 這很有趣,因爲它說你可能錯過了一個使用聲明。

To solve this: register the actual COM/ActiveX dll even if it's in the neighbor project, and add a reference through COM channel, not project channel. 要解決此問題:即使它位於鄰居項目中,也要註冊實際的COM / ActiveX dll,並通過COM通道而不是項目通道添加引用。 It will add Interop.ProjectName instead of ProjectName as a reference and this solves this strange bug. 它將添加Interop.ProjectName而不是ProjectName作爲參考,這解決了這個奇怪的錯誤。


#6樓

In my case I had: 在我的情況下,我有:

Referenced DLL : .NET 4.5 引用的DLL: .NET 4.5

Project : .NET 4.0 項目: .NET 4.0

Because of the above mismatch, the 4.0 project couldn't see inside the namespace of the 4.5 .DLL. 由於上述不匹配,4.0項目無法在4.5 .DLL的命名空間內看到。 I recompiled the .DLL to target .NET 4.0 and I was fine. 我重新編譯.DLL以目標.NET 4.0,我很好。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章