Event For Component Instancing?

  • Thread starter Thread starter localhost
  • Start date Start date
L

localhost

How can a given component know when it has been loaded by anything
else in the .NET Framework? I guess I'm looking for an event to trap.
This is not for ASP.NET, it is for a stand-alone C# object living
inside a discrete DLL.

Thanks.
 
Hello,

Thanks for your post. As I understand, you want to detect whether a .NET
class is instantiated from managed or unmanaged client. Please correct me
if there is any misunderstanding. I'd like to share the following
information with you:

As you know, a managed class is always created on .NET side. That is,
unmanaged client cannot access your managed component directly, it should
call through CCW (COM callable wrappers) instead. Please refer to the
following MSDN article for detailed information on CCW:

Calling a .NET Component from a COM Component
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/callnetfrcom.asp

One method comes up to my mind so far is that: In the constructor of your
managed class, throw and catch an exception so that you can get the call
stack, look up the call stack that will help you determine where the call
is originated from. I am afraid that there is no easy way.

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
You have misunderstood my question.

I have a .NET .dll. I have a .NET executable. When the .NET
executable is run, I the LoadFrom method in the Reflection class can
be used to load the dll. I want to know if the dll can detect when it
is loaded and inspected. I hope the dll has some kind of event that
is fired when it is loaded. Is that possible?

As far as I know, the dll can only "do something" when a class inside
it is instanced and the constructor fires. I am hoping there is an
alternative (I don't want to apply a class factory pattern if I don't
have to, but I will).

Thanks.
 
Back
Top