Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an existing namespace and have added a new class file with 2 classes defined in the same namespace. In one of the previously existing classes (same namespace) I can declare variables of both the new classes without error. But in another class (same namespace) - one of the declaration gives error CS0246 and the other one has no problem.

Stranger yet; if I add a third class - that one generates the same error.

Both classes are listed in Intellisense.

1) Since they are in the same assembly - it is not missing.
2) Since they are in the same namespace and one of them can be seen - using directive it not the problem.

Any ideas?
Updated 3-May-22 2:28am
[no name] 3-May-22 8:26am    
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'modbus' could not be found (are you missing a using directive or an assembly reference?) modbus1 C:\Users\PCAPP\source\repos\modbus1\modbus1\Form1.cs 17 Active
Dave Kreskowiak 3-May-22 8:50am    
If you've got a question, open your own question by going to the "quick answers" menu and click "Ask a question", and provide proper details on your problem.

Thanks for the efforts.

It turned out that it would build without errors if it was built by itself. But would generate errors when the whole solution was built.

The problem turned out to be related to linking. A member of our team has direct links, in another related project, to 2 of the files I was modifying. That project only needed those 2 files; it does not depend on any other assemblies in the solution. Unfortunately I was introducing dependencies on other classes in the original assembly that was not linked to the other project.

I have several possible workarounds and just need to decided which is the best solution.

Thank again!
Share this answer
Can you rule out that you haven't done any thing wrong as mentioned here:[^]

A simple typo could be creating the problem.
Share this answer
Since, everything is in order as stated by you, try Build->Clean Solution in Visual Studio, as sometimes when everything seemed to be correct, it helped me.
I am not sure that it will serve the purpose, but may be helpful.
It is a simple point not worth mentioning, but sometimes we may miss simple points.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900