This question is for interest sake. I’m working with a third-party library and came across the following documentation on a CMS.Security.Dummy class:
DO NOT DELETE THIS CLASS – This class prevents the compiler from
dropping entire namespace under .NET 4.0.
Does anybody know, or can anybody speculate why .NET 4 would drop the namespace if the dummy class were removed?
Because .NET 4 is explicitly named in the source code comment, I assume previous C# versions exhibit behaviour that do not require this dummy class. That’s purely speculative though.
Screen shot

Decompiled Source Code
#region Assembly CMS.SettingsProvider.dll, v4.0.30319
// ...\solution\wwwroot\Bin\CMS.SettingsProvider.dll
#endregion
using System;
namespace CMS.Security
{
// Summary:
// DO NOT DELETE THIS CLASS - This class prevents the compiler from dropping
// entire namespace under .NET 4.0.
public class Dummy
{
// Summary:
// DO NOT DELETE THIS CLASS - This class prevents the compiler from dropping
// entire namespace under .NET 4.0.
public Dummy();
}
}
A little-appreciated fact is that there is no such thing as a “namespace” from the point of view of the underlying CLR type system. Rather, it’s just a convention that we say that a type that contains periods in its name is “a member of a namespace”. Logically there is no difference at all between the legal code:
and the psuedo-code:
C# forces you to pretend this pleasant fiction is reality, but it is just a fiction — from the perspective of the CLR type system, of course. From the perspective of the C# compiler, of course namespaces are “real”. They just don’t correspond to anything in metadata other than a portion of the name of a type.
In short: if you make an assembly with an “empty” namespace then the “namespace” doesn’t exist at all in the compiled binary. A “namespace” only comes into existence when there is a type in the library that has periods in its name.
Now, why you would care about ensuring that an “empty” namespace has some presence in the binary form, I have no idea.
Nope. Every version of C# since 1.0 throws away empty namespaces.