> I was wading through code and noticed
> Castle.Core.Internal.ReflectionUtil.GetAssemblyNamed(String) uses
> LoadFile
> from here 
> http://stackoverflow.com/questions/1477843/difference-between-loadfile-and-loadfrom-with-net-assemblies
> use LoadFile when "you needed to use reflection on different copies of
> the same assembly"

This is a very simplified piece of advice. To decide whether to use
LoadFile or LoadFrom, you mainly need to decide which loader context
you want to use. In a nutshell, the context mainly decides how
assembly (and dependency) resolution works. An ordinary assembly load
uses the Load context. LoadFrom uses the LoadFrom context. Assemblies
are resolved within their context only; eg., a dependency from a
Loaded assembly to a LoadFrom'd assembly will not automatically be
resolved. (LoadFrom to LoadFrom will, on the other hand, even if the
assemblies were loaded from different paths. Load to Load will as
well, this is how default dependencies are resolved.)

LoadFile uses no context, ie., the loaded assemblies will not be used
for assembly resolution at all. (Although dependencies from a
LoadFile'd assembly to a Loaded assembly can be resolved.)

The fact that LoadFrom cannot be used to load multiple copies of the
same assembly is an effect of this: LoadFrom resolves in its own
context before loading an assembly, so it would detect the assembly is
already loaded.

Suzanne Cook's blog explains this in detail:
"http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57143.aspx";. (In
addition, 
"http://blogs.msdn.com/b/suzcook/archive/2003/09/19/loadfile-vs-loadfrom.aspx";
also describes differences between LoadFrom and LoadFile.)

That said, I've no idea what loader context
ReflectionUtility.GetNamedAssembly should actually use :)

Fabian

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Development List" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-devel?hl=en.

Reply via email to