Classes without namespaces (Error 1)  
Author Message
Skippy_sc





PostPosted: Visual C# IDE, Classes without namespaces (Error 1) Top

Hi,

I'm debugging someone else's code. The programmer is not using namespaces and all his classes are in different files with the name of the class as the filename.

Somehow, only on my machine, I get an error saying:

Error 1 The type or namespace name 'MyClass' could not be found (are you missing a using directive or an assembly reference )

Works fine on his computer.

How does the IDE resolve the "using" statement and, if someone is only writing classes without namespaces, how can the compiler find a class when it's being used as a type in another class (and file)

Plus, if a file is included in a project, doesn't the IDE "register" the possible use of all the classes defined inside that file Is there a "Path" variable that we need to set somewhere

Thanks,

Skip



Visual C#5  
 
 
Mark Benningfield





PostPosted: Visual C# IDE, Classes without namespaces (Error 1) Top

Hello All.

How does the IDE resolve the "using" statement and, if someone is only writing classes without namespaces, how can the compiler find a class when it's being used as a type in another class (and file)

Hence, the use of namespaces.

Skip:

If it works on his machine and not on yours, then you have to find out what the difference is. One or the other of you has something defined that the other doesn't.

HTH.



 
 
Figo Fei - MSFT





PostPosted: Visual C# IDE, Classes without namespaces (Error 1) Top

Hi, Skip

In .NET framework the namespace keyword is used to declare a scope. This namespace scope lets you organize code and gives you a way to create globally unique types. It allow for the logical grouping of related typed, and developers typically use them to make it easier to locate a particular type.

To the compiler, a namespace is simply an easy way of making a type's name longer and more likely to be unique by preceding the name with some symbols separated by dots. Using the  C# using directive and the Imports statement in VB is entirely optional. The C# using directive instructs the compiler to "try" prepending different prefixes to a type name until a match is found.

If you want to reference the class just in the same namespace, you don't have to locate the class in a particular namespace to refer, just use it! While in different namespaces you must tell the compiler where it belongs to.

And before we discuss why the code works well on other's machine while bombing error on yours, could you give me more details about the code

BR