Reputation: 5895
Is there a programmatic way to determine when an assembly itself has been loaded?
I know how to check for loaded assemblies out of the executing assembly, but I want to do it from "inside" the assembly that's going to be loaded.
This way I could determine that the application (which is using the loaded assembly) has been started, but no class from my loaded assembly has been instantiated / no method has been called thus far.
Upvotes: 0
Views: 1808
Reputation: 5797
What you are looking for is a function that is called when a module/assembly is loaded. In the pre-.NET world it was the DllMain function. A corresponding function exists in .NET but for whatever reason you can't create it in C# or VB.NET just in C++/CLI. It is called module constructor. You can manipulate your assembly to inject such module constructor. So whenever the assembly is loaded this function is called from inside the assembly before further access to this assembly. How to do it is explained here: http://einaregilsson.com/module-initializers-in-csharp/
Upvotes: 5