I thought I can get an reference to an object contained in the EXE if I load the .net assembly(which is an exe) into my own appdomain and get the object reference through refleciton.
Can I really do this?
Here is my sample code…
myDomain = AppDomain.CreateDomain("MyAppDomain");
myDomain.ExecuteAssembly(exePath);
Assembly myAssembly = myDomain.GetAssemblies().Single(a => a.FullName.Contains("TestAssembly"));
Type t = commandsAssembly.GetType("TestClass");
By any way can I get a reference to an object of this type?
Edit:
In the main method of my EXE I am creating an object of type TestClass, I want a reference to that object. What I thought is ExecuteAssembly will execute the exe in the new appdomain, so when the EXE is instantiated my object would be created. Please correct me if I am wrong. CreateInstance will create a new object but I want reference to my object which gets created when EXE is executed… May be I am thinking in a stupid way, please correct me…
Thanks in Advance
Try
commandsAssembly.CreateInstance ("TestClass");orActivator.CreateInstance (t);EDIT – after the addition that all living instances are of interest:
I think the only to achieve this is to write some sort of “debugger” which is really a tough call… some potentially usefull links
http://blogs.msdn.com/b/davbr/archive/2011/02/01/clrprofiler-v4-released.aspx
http://www.codeproject.com/Articles/122592/Writing-a-NET-debugger-part-1-Starting-the-debuggi
http://www.codeproject.com/Articles/122591/Writing-a-NET-debugger-part-2-Handling-events-and
http://www.codeproject.com/Articles/126142/Writing-a-net-debugger-part-3-symbol-and-source-fi
http://www.codeproject.com/Articles/132798/Writing-a-NET-debugger-part-4-breakpoints
http://msdn.microsoft.com/en-us/library/bb190764.aspx
http://msdn.microsoft.com/en-us/library/ms229861.aspx
The CLR profiler needs to do parts of you want – source is available so perhaps a good start…