Calling Load(AssemblyName) is not necessarily the same as calling Load(String). If the AssemblyName.CodeBase is not set, then they do do the same thing. So, if you’ve set the AssemblyName.Name, CultureInfo, public key token / public key and/or Version properties, it would be the same as if you had specified those properties in a String (as a display name) and passed that to Load(String).

If the CodeBase is set, but the Name is not, however, then it’s the same as calling Assembly.LoadFrom() on that CodeBase.

When both the CodeBase and the Name are set, then the bind is tried with all the given binding information except the CodeBase (so, again, just like calling Load(String)). If that succeeds, we’re done. But, if that fails, then the bind is tried again with just the CodeBase (just like LoadFrom()). If it fails again, then, of course, the whole bind fails. But, if it succeeds, then we verify that the binding properties in the AssemblyName match the found assembly. If they don’t match, a FileLoadException will be thrown for hresult FUSION_E_REF_DEF_MISMATCH.

So, setting both the CodeBase and the Name is useful for when you want to both load an assembly at a given path into the LoadFrom context, and verify that it has the public key token, etc. that you expect. Of course, as described above (and due to binding context rules), keep in mind that just because you call Load(AssemblyName) with a CodeBase, it does not mean that it will be loaded from that path.

Comments (7)

  1. Commonality says:

    Jon Flanders posts here about a problem he diagnosed recently about Assembly.LoadFrom() and Assembly.Load() behaving differently. The issue he basically…

  2. Terry Massey says:

    It is nice to finaly see who deals with by far my favorate thing in .net. The Assymbly.Load function is by far one of the best ways to dynamicly load modular/Componentized applications. I use this function extensivly with most of my projects, especialy when I need to run CRON or scheduled tasks. I have writen many a task manager where I take and I guess after waching the Channel 9 stuff is a bad thing to do but reading a folder that I place my dll’s/Asymblies in for dynamic loading of my jobs. I is nice to be able to load up an asymbliy with out having to register it like in COM or in the GAC.

    I should really spell check this but hey it is a blog and I am a developer.

  3. Jejo says:

    Hi. I’m trying to dynamically load/unload assemblies, as I am compiling them at runtime. Every time I compile a new version, I’d like to switch the assemblies. Is there some kind of workaround so that this is possible?

    I tried to load every assembly in a separate AppDomain, so I can do an .UnLoad on it, destroying all the loaded assemblies within.

    Another approach would be to run assemblies side-by-side based upon version info & strong names. I did not yet delve into that one.

    Now I’ve just read that assemblies used from other appdomains get loaded into the consuming appdomain, so the solution I depicted above only results in the same blocking situation.

    Maybe this is an egghead idea, maybe not. But it would be REAL nice to get some kind of dynamic unloading to work. After all, constantly loading new assemblies would be unnessecary memory usage.

  4. IcingDeath says:

    This goes for Load(),LoadFrom() and LoadFile() [duh!].

    When I have an executable trying to load Dll file X with dependency Y, the dll will fail to load unless y is located in the same path with the executable and not in the same path with the dll.

    Am i making any sense??? Is this the expected behavior? What happens if I wanna load a plugin with dependencies (other than the ones located in the GAC) and they are located in the same path with the DLL but not in the path of the .exe??

    Maybe this is a bug? Framework 1.1

  5. Seshagiri says:

    A majority of my applications/ libs are weakly named assemblies (I have no reason to make them strongly named).

    If I want to load these dynamically, what is the best method to use:

    Assembly.LoadFrom (or) Assembly.Load()?



  6. Hamid says:


    would you please help me?

    i wanna set transparent swf file in my form. i did add axshockwave and set swf file with it, but it dose not in transparent mode 🙁

    i will many thank you if you help me

    good luck

  7. Fernando Simonazzi says:


    By "If the CodeBase is set, but the Name is not, however, then it’s the same as calling Assembly.LoadFrom() on that CodeBase.", do you also mean that the assembly will be loaded in the LoadFrom context?