Get the root namespace (assembly namespace) of the loaded assembly
I am using a method GetTypeInfo()
to get a TypeInfo
class from an assembly.
With this I am trying to get the root namespace of this assembly (or is it called the namespace of the assembly?). But I cannot find there the property that this namespace gives me. There AssemblyQualifiedName
is a which is string
which has a root namespace in it. But there are other things as well like version number etc.
How can I get the root namespace of an assembly in .NET Core?
source to share
Assemblies do not have namespaces themselves, only types within an assembly. What you might be thinking about is "Assembly Name", which is often the same as "Default Namespace", which most types in an assembly will use.
Assembly assembly = //..
string name = assembly.GetName().Name;
GetName()
returns an object AssemblyName
that contains the fragments that are used to create AssemblyQualifiedName
. This feature is available in .NET Standard 1.0 , so it is available on all versions of .NET Core
source to share