When adding a new file (class) to the workspace in Visual Studio Code, an error occurs:

If you’re looking for a directive or an assembly reference?

The directives are not included in the Item file. In this case, if I change the name of the Item to Zitem , that is, the file appears after the Program class, the error will disappear. Why? How to fix it?

enter image description here enter image description here

  • So you have a class in Item.cs called "Item" and it is in the same namespace? Check again that this is so. Otherwise, to be honest, I do not see possible problems. IDE bug is obtained some. - John
  • Exactly. The Item.cs class in the same namespace. The point is in assembly referencies, but I do not understand how to add a link to this file manually. By the way, the error disappears if I delete this file and create the class Item.cs in new file via Intellisense. - NickF 4:04 pm
  • one
    Where did the old file come from? Can you visually distinguish between Russian and Latin letters - "a", "o", "e"? Me not. - Igor
  • Does Intellisense not offer the same solution to the same problem? Type to add these links automatically? And others tried the same classes or the problem in this? And if you transfer all the code from your class to the class created by the machine, then everything works? @Igor theme says ... - John
  • The old file came from this: PCM on the area in the first picture => New File. I did not confuse layouts) In general, if I add any file in this way, and it will be located earlier in alphabetical order than Program.cs, then nothing will work. - NickF

1 answer 1

The namespace must not be the same as the class name. Namespace Items class Item and then new Items.Item () will be no problem