How can I retrieve the default namesace of an assembly?

  • Thread starter Thread starter jj
  • Start date Start date
J

jj

I have an Assembly object that I need to get a resource stream from.
The name of the resource is of course based upon the default namespace,
not the assembly name. Is there a way to use reflection to get the
default namesace?

Thank you,

jj
 
jj,

There is no such thing as a default namespace for an assembly. An
assembly can contain types in any number of namespaces.

You should use attributes in your assembly (they can be applied on the
assembly level) to indicate what the resources to load are (since they seem
to be based in some part on the assembly).

Hope this helps.
 
I have an Assembly object that I need to get a resource stream from.
The name of the resource is of course based upon the default namespace,
not the assembly name. Is there a way to use reflection to get the
default namesace?

Not sure, but what I've done in the past is use 'GetManifestResourceNames'
to list all of the resources. Then I pick the one I'm looking for. This
can be better since different resources may be in different Namespaces.

-mdb
 
Thank you for the quick response,

What I have is an xslt file in the source directory of my project with
a build action of "Embedded Resource". When I make a call to
Assembly.GetManifestResourceStream() I need the assembly and the full
name. This full name is prefixed by the default namespace that is
defined in the properties. I would like to avoid having to use the
assembly path, the default namespace, and the class name to get to the
resource and instead get the default namespace from the Assembly
object. I can do this if I make sure that the default namespace is the
same as the assembly name, as it is by default, but since this is for a
framework for other developers to use, I would like to avoid this
requirement.
 
jj said:
Thank you for the quick response,

What I have is an xslt file in the source directory of my project with
a build action of "Embedded Resource". When I make a call to
Assembly.GetManifestResourceStream() I need the assembly and the full
name. This full name is prefixed by the default namespace that is
defined in the properties. I would like to avoid having to use the
assembly path, the default namespace, and the class name to get to the
resource and instead get the default namespace from the Assembly
object. I can do this if I make sure that the default namespace is the
same as the assembly name, as it is by default, but since this is for a
framework for other developers to use, I would like to avoid this
requirement.

The "default namespace" is purely a Visual Studio construct. As Michael
suggests, you could find all the names of resources and pick the one
you're after. If you only include one XSLT file per assembly, that
should be really easy. To be honest, it would be best if other
developers specified which resource name to use explicitly, IMO.
 
Back
Top