Dynamic Method Registration  
Author Message

PostPosted: .NET Base Class Library, Dynamic Method Registration Top

When I programmed in C++, I could LoadLib() a DLL which could then "automagically" call back to my process - so that it could "self-register" objects and such.  This was done through statically declared file-scope objects whose constructors were automatically called, simply because I had loaded the DLL.  And even if I didn't have that mechanism, there was also the "BOOL APIENTRY DllMain()" I could use for a similar purpose.

But with .net / C#, I know of no similar mechanism.  If I do "Assembly.LoadFile()," the assembly will load and then sit there like a lump.  Its up to "me" to make a first invocation into that assembly.  Is there something I'm missing   Is there a way to make an assembly I load with "LoadFile()" automatically start executing some piece of code   That would be very helpful.

Perhaps there is some attribute that can be applied to a method that effectively means "start executing the moment this assembly is loaded."  That would be **very** cool.

.NET Development18  
Mattias Sjogren

PostPosted: .NET Base Class Library, Dynamic Method Registration Top

The CLR supports this feature as of v2.0, but it's not exposed in C#.