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 1883
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.co m
"Joel" <jo******@hotma il.com> wrote in message
news:OX******** ******@TK2MSFTN GP12.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.Diagnost ics.StackTrace strace=new System.Diagnost ics.StackTrace( 1);
int c=strace.FrameC ount;
for(int i=0; i<c; i++)
{
System.Diagnost ics.StackFrame sframe=strace.G etFrame(i);
Type t=sframe.GetMet hod().Declaring Type.GetInterfa ce("IWip");
if(t!=null)
{
PropertyInfo pi=t.GetPropert y("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.c om> wrote in
message news:um******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:OX******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message
news:uP******** ******@TK2MSFTN GP10.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.Diagnost ics.StackTrace strace=new System.Diagnost ics.StackTrace( 1); int c=strace.FrameC ount; for(int i=0; i<c; i++) { System.Diagnost ics.StackFrame sframe=strace.G etFrame(i); Type t=sframe.GetMet hod().Declaring Type.GetInterfa ce("IWip"); if(t!=null) { PropertyInfo pi=t.GetPropert y("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.c om> wrote in message news:um******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:OX******** ******@TK2MSFTN GP12.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 instantiat e 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.c om> wrote in
message news:u8******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:uP******** ******@TK2MSFTN GP10.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.Diagnost ics.StackTrace strace=new System.Diagnost ics.StackTrace( 1); int c=strace.FrameC ount; for(int i=0; i<c; i++) { System.Diagnost ics.StackFrame sframe=strace.G etFrame(i); Type t=sframe.GetMet hod().Declaring Type.GetInterfa ce("IWip"); if(t!=null) { PropertyInfo pi=t.GetPropert y("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.c om> wrote in message news:um******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:OX******** ******@TK2MSFTN GP12.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 instantia te 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.co m
"Joel" <jo******@hotma il.com> wrote in message
news:u1******** ******@TK2MSFTN GP15.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.c om> wrote in message news:u8******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:uP******** ******@TK2MSFTN GP10.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.Diagnost ics.StackTrace strace=new System.Diagnost ics.StackTrace( 1); int c=strace.FrameC ount; for(int i=0; i<c; i++) { System.Diagnost ics.StackFrame sframe=strace.G etFrame(i); Type t=sframe.GetMet hod().Declaring Type.GetInterfa ce("IWip"); if(t!=null) { PropertyInfo pi=t.GetPropert y("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.c om> wrote in message news:um******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:OX******** ******@TK2MSFTN GP12.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 >instantiat e 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******@hotma il.com> wrote in message
news:uP******** ******@TK2MSFTN GP10.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.Diagnost ics.StackTrace strace=new System.Diagnost ics.StackTrace( 1); int c=strace.FrameC ount; for(int i=0; i<c; i++) { System.Diagnost ics.StackFrame sframe=strace.G etFrame(i); Type t=sframe.GetMet hod().Declaring Type.GetInterfa ce("IWip"); if(t!=null) { PropertyInfo pi=t.GetPropert y("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.c om> wrote in message news:um******** ******@TK2MSFTN GP12.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.co m
"Joel" <jo******@hotma il.com> wrote in message news:OX******** ******@TK2MSFTN GP12.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 instantiat e 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.
This object reference is passed into another object create within the same
|
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" marginheight="0"
marginwidth="0">
<frame name="topFrame" scrolling="auto" src="top.asp"
bordercolor="#cccc66" frameborder="yes" 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 is
displayed on a form (a datagrid on a form)
there is no database, but i created a dataset using the designer. One
Entity/Table is called Log and...
|
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 simply a tcp
listener
which creates a new client object and starts a new thread inside that
object to
|
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 "Sample" Object?
| |
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 object to be able to invoke a method
on my server object and given that the object is built in a C# Class DLL
shared between the client and server I'm...
|
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. The global
variables and global functions are hidden to prevent from accessing by the
programmers. All global functions share global variables....
|
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: 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |