Samer Ibrahim's Blog

The Samer I Warrior on battles with .NET



Which Blogs do I read?

AssemblyResolve event of an AppDomain

I got a comment from a gentleman by the name of Anthony DeRosa asking for more details relating to how to load an assembly from a network location from my earlier post regarding the GAC.  So even though I found that this is addressed elsewhere when I googled for it what the heck another entry won't hurt anyone.

Let's start with the Assembly.LoadFrom method which most people are familar with.  One can easily load an assembly from a network location just using that method alone which may solve most people's problem.  But what if you want to be able to only load the assembly from a location if the .NET framework can't find it on it's own or you need some other algorithm to locate assemblies.  Little known to most people, beyond just the simple probing and checking of the GAC that .NET does, there is an event fired before the framework gives up on loading your assembly.  The event is AppDomain.AssemblyResolve.  You can subscribe to that event and do a simple Assembly.LoadFrom from a location known to you or even do some fancy loading of your own based on some system you engineer.  There are also TypeResolve and ResourceResolve events in the AppDomain that let you handle those aspects of resolving the various dependencies of an AppDomain.

Of course if you are loading an assembly off the network you need to make some CAS changes.

Just Googling for resources I found these:

Also just as an FYI, there is also a ModuleResolve event of an Assembly.

Posted: May 02 2004, 08:04 PM by SamerEyeWarrior | with 3 comment(s)
Filed under:


BlindSniper said:

Don't stop posting such articles. I like to read blogs like this. Just add some pics :)

# January 23, 2010 1:09 AM