Elliot
Elliot

Reputation: 17

The type or namespace name does not exist - folders in C#

I'm sure there is a simple solution to this problem, but it has defeated me so far. Basically all I'm trying to do is include some classes in a separate folder in my c# project. Strangely this has been working just fine until today.

In the solution explorer I created a new folder called animations. I added the line to the main class:

using AnimationEditor.animations; (AnimationEditor is the solution name/namespace)

which throws the error:

Error 1 The type or namespace name 'animations' does not exist in the namespace 'AnimationEditor' (are you missing an assembly reference?)

As I said, I didn't have this error before today so I am a little confused.

Upvotes: 0

Views: 5111

Answers (2)

Scott Chamberlain
Scott Chamberlain

Reputation: 127593

If you don't have the the line namespace AnimationEditor.animations in the the class you are trying to reference you need to manually add it.

Those namespace statements do not get automatically added when you move a file, they only get automatically put in when you create a new file under the folder.

So your class should look like

namespace AnimationEditor.animations
{
    class MyClass
    {
        //snip
    }
}

As a side note, the .NET naming conventions state you should use a capital letter for those sub namespaces, capitalize the folder name and it will automatically capitalize the namespace for new files (you will need to manually change existing ones, just like moving)

Upvotes: 1

Panu Oksala
Panu Oksala

Reputation: 3438

If you drag files to another folder (or add them) in visual studio, namespace does not change automatically (atleast in 2010). Check namespace of AnimationEditor class.

Upvotes: 0

Related Questions