473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Assembly.GetCallingAssembly().GetType().Namespace

Greeting,

I'm working on a class managing resources (satelite).

public CResMgr()
{
Assembly objClient = Assembly.GetCallingAssembly();
_objResMgr = new ResourceManager(objClient.GetType().Namespace + '.'
+ DefaultBaseName, objClient);

The result of objClient.GetType().Namespace is "System.Reflection",
not what I'm expecting.
Presently, I workaround by passing the caller's Type.

_objResMgr = new CResMgr(this.GetType());

public CResMgr(Type objCaller)
{
_objResMgr = new ResourceManager(objCaller.Namespace + '.' +
DefaultBaseName, objCaller.Assembly);

Is there a way to dynamically to retrieve the Namespace of the
calling obj?
Jul 21 '05 #1
3 4181
Kelmen Wong <ke****@hotmail.com> wrote:
I'm working on a class managing resources (satelite).

public CResMgr()
{
Assembly objClient = Assembly.GetCallingAssembly();
_objResMgr = new ResourceManager(objClient.GetType().Namespace + '.'
+ DefaultBaseName, objClient);

The result of objClient.GetType().Namespace is "System.Reflection",
not what I'm expecting.
Why not? The Assembly type is in the System.Reflection namespace, and
you're calling GetType() on an instance of Assembly.
Presently, I workaround by passing the caller's Type.

_objResMgr = new CResMgr(this.GetType());

public CResMgr(Type objCaller)
{
_objResMgr = new ResourceManager(objCaller.Namespace + '.' +
DefaultBaseName, objCaller.Assembly);

Is there a way to dynamically to retrieve the Namespace of the
calling obj?


I don't believe so.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hi,

As it turns out there is a way to find out what called your assembly. It
seems to work in both Debug and Release.

First of all, do a stack trace.

C#
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);

then, to find out what called your code, just check the stack.. The first
item in the stack will be the function with the above line of code in it, the
second item in the stack will be the Method that called your code..

So, to find out the type, use the line below:

C#
trace.GetFrame(1).GetMethod().DeclaringType

As I said, this seems to work well in most situations.

Have fun..

Eddie de Bear

"Kelmen Wong" wrote:
Greeting,

I'm working on a class managing resources (satelite).

public CResMgr()
{
Assembly objClient = Assembly.GetCallingAssembly();
_objResMgr = new ResourceManager(objClient.GetType().Namespace + '.'
+ DefaultBaseName, objClient);

The result of objClient.GetType().Namespace is "System.Reflection",
not what I'm expecting.
Presently, I workaround by passing the caller's Type.

_objResMgr = new CResMgr(this.GetType());

public CResMgr(Type objCaller)
{
_objResMgr = new ResourceManager(objCaller.Namespace + '.' +
DefaultBaseName, objCaller.Assembly);

Is there a way to dynamically to retrieve the Namespace of the
calling obj?

Jul 21 '05 #3
Hello Eddie,

Thanks for tip. I do aware about the StackTrace object, but not
going to work over it, due to a known limitation:

StackTrace might not report as many method calls as expected, due to
code transformations that occur during optimization.

The above statement is taken from the MSDN StackTrace object
remarks.

Presently, I'm adopting passing the Type from the caller to it.

"Eddie de Bear" <Ed*********@discussions.microsoft.com> wrote in message news:<B9**********************************@microso ft.com>...
Hi,

As it turns out there is a way to find out what called your assembly. It
seems to work in both Debug and Release.

First of all, do a stack trace.

C#
System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(true);

then, to find out what called your code, just check the stack.. The first
item in the stack will be the function with the above line of code in it, the
second item in the stack will be the Method that called your code..

So, to find out the type, use the line below:

C#
trace.GetFrame(1).GetMethod().DeclaringType

As I said, this seems to work well in most situations.

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Theodore | last post by:
Hi, from within an executable I am calling class A located in a dll file which in turn calls class B located in another dll file. I want class B to be able to resolve the last entry assembly. By...
3
by: Chris Becker | last post by:
The following code works. My problem is that I don't want to have to hardcode the string that I set resourceName to in the code. Is there a way for me to determine the namespace of the assembly...
2
by: Marty | last post by:
Hi, I am using C#.NET 2003. First step: When I call System.Reflection.Assembly.GetCallingAssembly().GetName().Name; in debug mode from the IDE, I get a specific Assembly name. Second step:...
0
by: Shawn Hogan | last post by:
I'm getting two different results when I call System.Reflection.Assembly.GetCallingAssembly when compiling in Release and debug modes. When i compile my application using the "Debug" configuration...
1
by: Michael Maes | last post by:
Hello, If you want to have the Assembly who is Calling a certain Method in another one, you use 'GetCallingAssembly'. So far no problem. However: If you have the following Architecture: ...
4
by: Phil Galey | last post by:
I created an About box and am able to get all the assembly information from the program to show up in the About box except the Version. I created the About box as a separate Windows application,...
3
by: Kelmen Wong | last post by:
Greeting, I'm working on a class managing resources (satelite). public CResMgr() { Assembly objClient = Assembly.GetCallingAssembly(); _objResMgr = new...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.