LoadFile vs. LoadFrom
May 29th, 2008 by kerrysoft and tagged CRM solution, Web, workflow softwareBe measured - these aren’t the same thing.
- LoadFrom() works through Fusion and can be redirected to another assembly at a dissimilar path but with that same identity if one is already loaded in the LoadFrom context.
- LoadFile() doesn’t bind through Fusion at all - the loader simply operates in front and loads just* what the caller called for. It doesn’t use either the Load or the LoadFrom context.
And so, LoadFrom() unremarkably yields you what you asked for, but not needs. LoadFile() is for those who rattling, very desire precisely what is quested. (*All the same, starting in v2, policy will be applied to both LoadFrom() and LoadFile(), so LoadFile() won’t necessarily be exactly what was requested. Also, starting in v2, if an assembly with its identity is in the GAC, the GAC copy will be used instead. Utilize ReflectionOnlyLoadFrom() to charge just what you desire - but, note that assemblies charged that way can’t be put to death.)
LoadFile() has a catch. Since it doesn’t use a obligating context, its dependencies aren’t mechanically found in its directory. If they aren’t uncommitted in the Load context, you would have to take the AssemblyResolve event in order to bind to them.
Indeed, which one should you employ? That bets on which holding context is justly for you and whether it counts that the LoadFrom context may airt the bind. Regarding the latter:
- If no other code can lade assemblies in your AppDomain, your LoadFrom() call can keep a redirect* by exactly not loading up anything else with a twin identity.
- If you do require to lade a duplicate, you could catch off with it by loading up it into anything other than the LoadFrom context (or into another AppDomain) rather.
- But, perhaps the redirect is really o.k.. Are they indistinguishable assemblies, just now at unlike paths? If yes, it may be good to take chances the redirect unless its dependencies aren’t uncommitted in the dir of the first one charged.
- Or, are they maybe unlike bits, simply with the same assembly identity? If indeed, it may be insecure to chance the redirect: perchance you’ll catch an more-updated/not-as-updated version which you didn’t ask. Or, if it’s not powerfully-called, perhaps this is a third-party’s assembly, totally unrelated to the one you require.
Relating Posts:
Silverlight FlickR Example
Posted in Technology |