Basically I have a CS file defining an internal class, then I copy to various of CS projects. And the assemblies of these CS projects will be loaded in an application. The program seems to be running just fine.
However, having multiple classes with the same class name in the same namespace make me feel uneasy even if they are internal within each assembly.
Is a class uniquely identified through class name, namespace as well as assembly in an AppDomain?
Is a class uniquely identified through class name, namespace as well as assembly in an AppDomain?
Short answer: yes.
Longer answer:
There are a few subtle points to consider.
First, from the CLR perspective there is no such thing as a "namespace". The name of the string type is System.String
as far as the CLR is concerned. So it is more accurate to say that from the CLR perspective, a type is uniquely identified by its name and assembly.
Second, types may be nested. So types are actually uniquely identified by their name, containing type (if there is one) and assembly.
Third, types may be generic. Foo.Bar
and Foo.Bar<T>
are different types. So types are identified by their name, containing type, assembly, and generic arity.
Fourth, and this is the weird one, the CLR considers types in assemblies loaded with Load
different than types in the same assembly loaded with LoadFrom
. You can end up with situations where the CLR tells you that type Foo in assembly Bar is not compatible with type Foo in assembly Bar, and boy, is that confusing.
While it makes things confusing all your internal classes only exist in their respective assemblies so they are autonomous and will not be seen by the other classes in the other assembly.
But from a maintenance and simplicity perspective it should be put at the top of the house keeping tasks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With