471,325 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

How can I retrieve the default namesace of an assembly?

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

Dec 19 '05 #1
4 7165
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"jj" <jo**************@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
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

Dec 19 '05 #2
"jj" <jo**************@gmail.com> wrote in news:1135018800.397615.108390
@g43g2000cwa.googlegroups.com:
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
Dec 19 '05 #3
jj
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.

Dec 19 '05 #4
jj <jo**************@gmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Edward Diener | last post: by
3 posts views Thread by Marty | last post: by
2 posts views Thread by Steve Barnett | last post: by
74 posts views Thread by Zytan | last post: by
5 posts views Thread by =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post: by
7 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
10 posts views Thread by =?Utf-8?B?SmFtZXMgV29uZw==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.