Given an instance of System.Reflection.Assembly
.
The root namespace is the mainspace of the . NET Framework libraries. It may happen that someone creates a type or a namespace that will conflict with ones from the . NET Framework.
GetType("NAMESPACE.
VB.NET automatically prefixes the root namespace set in the project properties to the namespace of each class. This is different from C#, where the full namespace must be declared each time.
The main difference between namespace and assembly is that a namespace is a logical group of related classes that can be used by the languages targeted by Microsoft . NET framework, while Assembly is a building block of .
I have come across this dilemma plenty of times when I want to load a resource from the current assembly by its manifest resource stream.
The fact is that if you embed a file as a resource in your assembly using Visual Studio its manifest resource name will be derived from the default namespace of the assembly as defined in the Visual Studio project.
The best solution I've come up with (to avoid hardcoding the default namespace as a string somewhere) is to simply ensure your resource loading code is ALWAYS happening from inside a class that's also in the default namespace and then the following near-generic approach may be used.
This example is loading an embedded schema.
XmlSchema mySchema; string resourceName = "MyEmbeddedSchema.xsd"; string resourcesFolderName = "Serialisation"; string manifestResourceName = string.Format("{0}.{1}.{2}", this.GetType().Namespace, resourcesFolderName, resourceName); using (Stream schemaStream = currentAssembly.GetManifestResourceStream(manifestResourceName)) mySchema = XmlSchema.Read(schemaStream, errorHandler);
See also: How to get Namespace of an Assembly?
Edit: Also noticed a very detailed answer to the question I'm answering at http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/3a469f5d-8f55-4b25-ac25-4778f260bb7e
Another edit in case people with same question come looking: Excellent idea to solve the resource-loading question here: How get the default namespace of project csproj (VS 2008)
Not possible. Nothing specifies a "Root" namespace. The default namespace in the options is a visual studio thing, not a .net thing
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