Namespaces have no bearing on accessibility / visibility in C#; they are simply prefixes to type names to enable grouping of similar types together, for use with things like using
statements. It's essentially a compile-time concept, the runtime doesn't recognize namespaces as logical entities and requires fully-qualified names in the compiled code.
Instead, access is done on a per-assembly basis. An assembly is the .dll
or .exe
file each C# project produces. The same namespace may appear in multiple assemblies, and multiple namespaces may appear in the same assembly.
Marking something internal
means "allow access to it from anywhere in the same assembly as where this thing is declared". So if your unit tests are in a different assembly (as they should be, unless you want to ship your unit tests to customers!), they won't be able to access types in the MyNamespace
, regardless of what namespace the tests are declared in.
However, you can have your product assemblies allow an exception to this rule with the InternalsVisibleTo
attribute. See this answer for details.