I am writing a C# assembly that is completely independent from its host. This assembly doesnt have a single functional point of entry (it has a lot of objects that can be used in various ways).
Is there a way i can be notified on the first time, just once, that my assembly is loaded/and or being used
I need to know this in order to trigger an initialization of a resource.
Thanks.

can my C# assembly know when it's been loaded?
Andrés Sebastian Nagy
> Did n0n4m3's suggestion help you
I don't see how it could. There is a bootstrapping problem there. In order to hook the AssemblyLoad event, you would need to have code running in the assembly. And if you already have code running in the assembly, the problem is already solved, you can initialize the resource easily without needing to hook any event.
Christian Graus provided a more sensible solution, make the resource that needs to be initialized available as a static property, and lazy initialize it.
msuser-ngm
Hi Steve,
Just a followup on this post.
Did n0n4m3's suggestion help you I am wondering if you have any questions or concerns about this issue.
If you need further assistance, please do not hesitate to let me know.
Best regards,
Peter Huang
John Murdoch
Make the resource available as a property, and then lazy initialise it ( that is, initialise it the first time it is accessed ).
NewC#
to know when the assembly is loaded add an event handler for the AssemblyLoad event of you currentdomain:
AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(MyAssemblyLoadEventHandler);
static void MyAssemblyLoadEventHandler(object sender, AssemblyLoadEventArgs args)
{
Console.WriteLine("Assembly loaded: " + args.LoadedAssembly.FullName);
}