all groups > dotnet clr > november 2007 >
You're in the

dotnet clr

group:

Is there a way to execute code on Assembly loading?


Is there a way to execute code on Assembly loading? Simon Egli
11/8/2007 4:18:32 AM
dotnet clr:
Hello,

I have an assembly A that implements additional features for another
assembly B and should link itself automatically into the mechanisms of B
when it is loaded. Is there a way to get code executed in assembly A without
explicitly calling a method in A?

Thanx,

Simon
Re: Is there a way to execute code on Assembly loading? Alexander Vasilevsky
11/8/2007 5:26:27 PM
Please use interfaces.

http://www.alvas.net - Audio tools for C# and VB.Net developers


"Simon Egli" <simon_egli65@hotmail.com> ???????/???????? ? ????????
?????????: news:13fad$47328017$544a4183$30309@news.hispeed.ch...
[quoted text, click to view]

Re: Is there a way to execute code on Assembly loading? Willy Van den Driessche
11/9/2007 12:39:52 AM
reflection allows you to call any code (within the .NET CAS security
limits).

[quoted text, click to view]
Re: Is there a way to execute code on Assembly loading? Ben Voigt [C++ MVP]
11/12/2007 10:31:21 AM

[quoted text, click to view]

Yes and no.

No, because assembly A won't be loaded until you call a method in A. Yes,
because using type initializers (static constructor or .cctor) you can run
code of your choice before any other method is called for the first time.

If you are loading assembly A via reflection (Assembly.Load or
Assembly.LoadFrom) then place a custom attribute on assembly A to designate
an entrypoint that the plugin loader should call. You'll have to add this
feature to the plugin loader, but it will end up being reusable.

[quoted text, click to view]

AddThis Social Bookmark Button