2

A project that I've been working on for a long time without any problems suddenly started throwing errors such as

The type or namespace name 'xxx' does not exist in the namespace 'yyy' (are you missing an assembly reference)?

In this case, the namespaces were all core .Net libraries such as System.Data, Linq, and IO that I've been using without any problems.

I've worked through all of the issues in this question such as making sure all the projects in the workspace are using the same version of .Net for the Target Framework setting.

I removed all the libraries in question and re-added them but the problem persisted. I doubt they libraries themselves are corrupted as I reference them in other projects within the solution.

Community
  • 1
  • 1
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104

5 Answers5

4

After rolling back through my work with TFS I managed to work out what I'd done that had created this error: I'd added a folder called "System" to my project and put a class file in it.

This is an easy issue to reproduce: create a project, add a folder called system to it (it will still compile at this point) and then create a .cs file in it, that's when all the fun errors will occur.

The problem stems from the name of the "System" folder which leads to any files created in it being under the namespace ".System".

I can understand why having a folder / namespace called "System" would cause problems now but I think it would help if Visual Studio warned when creating a folder / namespace of such a name to stop this problem happening in the first place. I've logged a bug with MS, at least having this logged might help any other people who have made the same mistake as me!

GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
1

I had the same issue after my system shut down unexpectedly and even though VS tried to restore, the problem popped up.

I had two projects in my Solution Explorer. To solve this, I right-clicked the project that was associated with the error message and selected 'Build'.

After that, the issue was resolved.

Just to add that the problem was permanently solved after I added a reference to the 'project' from the other 'project'.

Okpo
  • 375
  • 4
  • 9
1

I renamed the namespace of the file I was referencing from myproject.shared.constants to myproject.SOMETHING.shared.constants

After that It suggested "use myproject.SOMETHING.shared.constants" as suggestion. I renamed it back to myproject.shared.constants and then it worked.

Enrico
  • 2,734
  • 1
  • 27
  • 40
1

Try to Clean and Then Rebuild the dll file .I was experiencing the same problem tried different suggestions from internet but none of them work.But it will. In case you don't know how follow these steps:

  1. open your dll project file. 2.click on solution Explorer Right click on Your Dll Project Name you will find Clean and Rebuild Option.
1

In my case I just set alias in using statement.

Like this:

using aliasName = yyy.xxx;

Then just use aliasName.something and it worked!

For me, I have multiple nested folders so maybe the compiler was confused.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83