Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Soft Gallery
    • autosvnbackup.sh
    • VBScript Snippets
  • Contact Me
  • Welcome

Assembly Initialization

Nicolas Galler | December 31, 2006

It appears that there is no facility in .NET to automatically call an initialization method when the assembly is loaded. This is a bit annoying for libraries since they will often require some initialization. So far I have found 2 work-around, neither of which are terribly satisfying:

  • Have a static initializer on the classes that are going to be called first when using the library. Obviously this is not usable in every case…
  • Register a handler for the assembly load event – this handler could then check the assembly for an initializer class. The easiest way I have found to achieve that was to define the initializer (with initialization done either in the constructor or in a static initializer) as an assembly level attribute, stick it on the assembly for the library, and have the assembly load event handler call the GetCustomAttributes method. I was actually hoping that .NET would be tricked into calling my attribute since it was an assembly attribute, sadly it seems it does not actually instantiate those attributes until someone tries reading them… So with this method I still need to have one initializer called manually to initialize the event handler.

There was a 3rd alternative which would be to just load all the types in the assembly whenever it is loaded (i.e. from the Load event handler)… then any static initializer would be called… seems like it could be a performance hit though so I decided to go with the more explicit approach.

Categories
Programming
Comments rss
Comments rss
Trackback
Trackback

« NAnt Weird Crashes IE7 Popup Blocker aaargh »

Leave a Reply

Click here to cancel reply.

Categories

  • Dojo (1)
  • Experiments (4)
  • Force.com (2)
  • Interesting (1)
  • Javascript (3)
  • MSCRM (1)
  • Programming (63)
  • Rant (3)
  • Saleslogix (41)
  • Tricks (8)
  • Uncategorized (32)

Post History

  • 2011
    • January (3)
    • February (2)
    • March (1)
  • 2010
    • January (3)
    • March (3)
    • April (2)
    • August (2)
    • October (4)
    • November (1)
    • December (2)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox