OnLoad Event for a .Net DLL?

D

David White

Is there some way for code to be triggered for execution when a .Net 2 DLL file
is loaded? I need to perform some initialization work (like loading other
DLLs). Thanks.
 
M

Mattias Sjögren

David,
Is there some way for code to be triggered for execution when a .Net 2 DLL file
is loaded? I need to perform some initialization work (like loading other
DLLs). Thanks.

Yes, but whether or not you can take advantage of it depends on which
language you're coding in.

Can't you do your initialization work in a static constructor?


Mattias
 
D

David White

Thanks. I would be coding in C# here. I do think I could manage to initialize
on first use of a contained class. But there may well be a substancial delay
between this DLL being loaded and a class inside it actually getting used. So I
was hoping that (a) I could use that time to do some work and (b) that if there
was some initialization error it could be reported sooner rather than later.
 
M

Mattias Sjögren

Thanks. I would be coding in C# here.

OK, it doesn't support defining a module initializer.

I do think I could manage to initialize
on first use of a contained class. But there may well be a substancial delay
between this DLL being loaded and a class inside it actually getting used.

Where's the DLL being loaded from? Keep in mind that the CLR doesn't
load assemblies until they are needed, so unless the client explicitly
uses something like Assembly.Load it will not be loaded in advance.


Mattias
 
Joined
Jul 4, 2010
Messages
3
Reaction score
0
The same issue

I have the same issue and have been finding a way to trigger an event handler when the assembly is being loaded but no luck. Putting it inside a static constructor does not work. It's so-called lazy load.

----------
ftp component | sftp component
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top