HighTechTalks DotNet Forums  

Is there a way to execute code on Assembly loading?

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss Is there a way to execute code on Assembly loading? in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Simon Egli
 
Posts: n/a

Default Is there a way to execute code on Assembly loading? - 11-07-2007 , 09:18 PM






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


Reply With Quote
  #2  
Old   
Alexander Vasilevsky
 
Posts: n/a

Default Re: Is there a way to execute code on Assembly loading? - 11-08-2007 , 09:26 AM






Please use interfaces.

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


"Simon Egli" <simon_egli65 (AT) hotmail (DOT) com> ???????/???????? ? ????????
?????????: news:13fad$47328017$544a4183$30309 (AT) news (DOT) hispeed.ch...
Quote:
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



Reply With Quote
  #3  
Old   
Willy Van den Driessche
 
Posts: n/a

Default Re: Is there a way to execute code on Assembly loading? - 11-08-2007 , 05:39 PM



reflection allows you to call any code (within the .NET CAS security
limits).

"Simon Egli" <simon_egli65 (AT) hotmail (DOT) com> wrote

Quote:
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


Reply With Quote
  #4  
Old   
Ben Voigt [C++ MVP]
 
Posts: n/a

Default Re: Is there a way to execute code on Assembly loading? - 11-12-2007 , 10:31 AM




"Simon Egli" <simon_egli65 (AT) hotmail (DOT) com> wrote

Quote:
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?
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.

Quote:
Thanx,

Simon



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.