I need to inspect the current AppDomain for an object that implements a
certain interface and get a property from the object. I know how to find out
what class implements my interface but Reflection only lets me instantiate a
new object. I want to get the property value from the already running
object.
Thanks.
</joel> 6 1876
Joel,
You will have to implement a way to make the object discoverable then.
The best way to do this (since the scope is the app domain) is to have a
static method or property which will give you the object you want.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message
news:OX**************@TK2MSFTNGP12.phx.gbl... I need to inspect the current AppDomain for an object that implements a certain interface and get a property from the object. I know how to find out what class implements my interface but Reflection only lets me instantiate a new object. I want to get the property value from the already running object.
Thanks.
</joel>
Nicholas,
But that's the problem. I don't know what object it is. I can use the
StackTrace to "walk up" the stack and find which class implements my
interface like this:
System.Diagnostics.StackTrace strace=new System.Diagnostics.StackTrace(1);
int c=strace.FrameCount;
for(int i=0; i<c; i++)
{
System.Diagnostics.StackFrame sframe=strace.GetFrame(i);
Type t=sframe.GetMethod().DeclaringType.GetInterface("I Wip");
if(t!=null)
{
PropertyInfo pi=t.GetProperty("IsWip");
}
}
but now I want to get a reference to the object that's running.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:um**************@TK2MSFTNGP12.phx.gbl... Joel,
You will have to implement a way to make the object discoverable then. The best way to do this (since the scope is the app domain) is to have a static method or property which will give you the object you want.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:OX**************@TK2MSFTNGP12.phx.gbl...I need to inspect the current AppDomain for an object that implements a certain interface and get a property from the object. I know how to find out what class implements my interface but Reflection only lets me instantiate a new object. I want to get the property value from the already running object.
Thanks.
</joel>
Joel,
You can't do this. Reflection will not allow you to get arbitrary items
on the stack.
If you want access to this, you will have to hook into the CLR (through
unmanaged code through the profiling APIs, most likely).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message
news:uP**************@TK2MSFTNGP10.phx.gbl... Nicholas,
But that's the problem. I don't know what object it is. I can use the StackTrace to "walk up" the stack and find which class implements my interface like this:
System.Diagnostics.StackTrace strace=new System.Diagnostics.StackTrace(1); int c=strace.FrameCount; for(int i=0; i<c; i++) { System.Diagnostics.StackFrame sframe=strace.GetFrame(i); Type t=sframe.GetMethod().DeclaringType.GetInterface("I Wip"); if(t!=null) { PropertyInfo pi=t.GetProperty("IsWip"); } }
but now I want to get a reference to the object that's running.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:um**************@TK2MSFTNGP12.phx.gbl... Joel,
You will have to implement a way to make the object discoverable then. The best way to do this (since the scope is the app domain) is to have a static method or property which will give you the object you want.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:OX**************@TK2MSFTNGP12.phx.gbl...I need to inspect the current AppDomain for an object that implements a certain interface and get a property from the object. I know how to find out what class implements my interface but Reflection only lets me instantiate a new object. I want to get the property value from the already running object.
Thanks.
</joel>
It doesn't have to be via the StackTrace, that was just a way I could walk
bakwards looking for the Interface implementation I wanted. Is there some
other way? Thanks for your help.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u8**************@TK2MSFTNGP12.phx.gbl... Joel,
You can't do this. Reflection will not allow you to get arbitrary items on the stack.
If you want access to this, you will have to hook into the CLR (through unmanaged code through the profiling APIs, most likely).
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:uP**************@TK2MSFTNGP10.phx.gbl... Nicholas,
But that's the problem. I don't know what object it is. I can use the StackTrace to "walk up" the stack and find which class implements my interface like this:
System.Diagnostics.StackTrace strace=new System.Diagnostics.StackTrace(1); int c=strace.FrameCount; for(int i=0; i<c; i++) { System.Diagnostics.StackFrame sframe=strace.GetFrame(i); Type t=sframe.GetMethod().DeclaringType.GetInterface("I Wip"); if(t!=null) { PropertyInfo pi=t.GetProperty("IsWip"); } }
but now I want to get a reference to the object that's running.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:um**************@TK2MSFTNGP12.phx.gbl... Joel,
You will have to implement a way to make the object discoverable then. The best way to do this (since the scope is the app domain) is to have a static method or property which will give you the object you want.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:OX**************@TK2MSFTNGP12.phx.gbl... I need to inspect the current AppDomain for an object that implements a certain interface and get a property from the object. I know how to find out what class implements my interface but Reflection only lets me instantiate a new object. I want to get the property value from the already running object.
Thanks.
</joel>
Joel,
Unfortunately, no, there is not. Unless you make the instance
discoverable by some means, your only option is to hook into the CLR through
the profiling API.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP15.phx.gbl... It doesn't have to be via the StackTrace, that was just a way I could walk bakwards looking for the Interface implementation I wanted. Is there some other way? Thanks for your help.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:u8**************@TK2MSFTNGP12.phx.gbl... Joel,
You can't do this. Reflection will not allow you to get arbitrary items on the stack.
If you want access to this, you will have to hook into the CLR (through unmanaged code through the profiling APIs, most likely).
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:uP**************@TK2MSFTNGP10.phx.gbl... Nicholas,
But that's the problem. I don't know what object it is. I can use the StackTrace to "walk up" the stack and find which class implements my interface like this:
System.Diagnostics.StackTrace strace=new System.Diagnostics.StackTrace(1); int c=strace.FrameCount; for(int i=0; i<c; i++) { System.Diagnostics.StackFrame sframe=strace.GetFrame(i); Type t=sframe.GetMethod().DeclaringType.GetInterface("I Wip"); if(t!=null) { PropertyInfo pi=t.GetProperty("IsWip"); } }
but now I want to get a reference to the object that's running.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:um**************@TK2MSFTNGP12.phx.gbl... Joel,
You will have to implement a way to make the object discoverable then. The best way to do this (since the scope is the app domain) is to have a static method or property which will give you the object you want.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:OX**************@TK2MSFTNGP12.phx.gbl... >I need to inspect the current AppDomain for an object that implements a >certain interface and get a property from the object. I know how to >find out what class implements my interface but Reflection only lets me >instantiate a new object. I want to get the property value from the >already running object. > > Thanks. > > </joel> >
Have the object's method insert a reference to the object into a data slot
in the current thread (and restore the previous value when the method
returns.) Yoiu can now find the object via Thread.GetData().
"Joel" <jo******@hotmail.com> wrote in message
news:uP**************@TK2MSFTNGP10.phx.gbl... Nicholas,
But that's the problem. I don't know what object it is. I can use the StackTrace to "walk up" the stack and find which class implements my interface like this:
System.Diagnostics.StackTrace strace=new System.Diagnostics.StackTrace(1); int c=strace.FrameCount; for(int i=0; i<c; i++) { System.Diagnostics.StackFrame sframe=strace.GetFrame(i); Type t=sframe.GetMethod().DeclaringType.GetInterface("I Wip"); if(t!=null) { PropertyInfo pi=t.GetProperty("IsWip"); } }
but now I want to get a reference to the object that's running.
</joel>
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:um**************@TK2MSFTNGP12.phx.gbl... Joel,
You will have to implement a way to make the object discoverable then. The best way to do this (since the scope is the app domain) is to have a static method or property which will give you the object you want.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Joel" <jo******@hotmail.com> wrote in message news:OX**************@TK2MSFTNGP12.phx.gbl...I need to inspect the current AppDomain for an object that implements a certain interface and get a property from the object. I know how to find out what class implements my interface but Reflection only lets me instantiate a new object. I want to get the property value from the already running object.
Thanks.
</joel>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Nick Zdunic |
last post by:
I have a remotable object running in my host application.
The host starts up and creates the object. Within a method to start the
remote object doing its thing it creates an object.
...
|
by: JJ |
last post by:
I'm working with a web site that has frames defined as:
<frameset rows="60,*" frameborder="yes" border="0" framespacing="0" cols="*"
bordercolor="#eeeeee" topmargin="0" leftmargin="0"...
|
by: - R |
last post by:
Hello all.
I'm new to .Net so please help me out.
I have a application with several "Threads" running to observe various
things. From time to time each thread need to add an log entry, which...
|
by: Friskusen |
last post by:
Hello VB.net programmers !
I'm just trying to understand what happens with an object which is
initialised
over and over again.
The code fragment below illustrates my problem. This code is...
|
by: Tim |
last post by:
I have a C# executable that has a class, say "Sample" which is a singleton.
The exe is running and the class is loaded. From another exe, can I get a
reference to the running instance of the...
|
by: Grant Schenck |
last post by:
Hello,
I have a Windows Service developed in C# .NET. I'm making it a remote
server and I can, via an IPC Channel, expose methods and call them from a
client. However, I now want my remoted...
|
by: David Lozzi |
last post by:
Hello there,
I'm getting the following error
System.NullReferenceException: Object reference not set to an instance of an
object.
at shopping_bag.GetBagTotals()
|
by: Bryan Parkoff |
last post by:
I write my large project in C++ source code. My C++ source code
contains approximate four thousand small functions. Most of them are
inline. I define variables and functions in the global scope....
|
by: Astley Le Jasper |
last post by:
Sorry for the numpty question ...
How do you find the reference name of an object?
So if i have this
bob = modulename.objectname()
how do i find that the name is 'bob'
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |