I was looking at the msdn documentation and I am still a little confused on what exactly is the difference between using LoadFile
and LoadFrom
when loading an assembly. Can someone provide an example or an analogy to better describe it. The MSDN documentation confused me more. Also, Is ReflectionOnlyLoadFrom
the same as LoadFrom
except that it loads the assembly only in reflection mode.
Since my .NET experience is not the greatest, here are some questions regarding the MSDN documentation using LoadFile:
1) What does it mean by LoadFile
examines assemblies that have the same Identity, but are located in different paths? What is the identity (example)?
2) It states the LoadFile
does not load files into the 'LoadFrom Context' and does not resolve dependencies using the load path. What does this mean, can someone provide an example?
3) Lastly, it states that LoadFile
is useful in this limited scenario because LoadFrom cannot load assemblies that have the same identities but different paths; it will only load the first such assembly, which again brings me to the same question, what is the assemblies identity?
Does this clear it up?
Edit: to answer the questions you raised in your revised question, you definitely want to read Suzanne Cook on Assembly Identity.
There are a lot of rules that govern how assemblies are loaded, and some of them have to do with how they resolve dependencies - if your AssemblyA is dependent on AssemblyB, where should .NET look to find AssemblyB? In the Global Assembly Cache, the same directory it found AssemblyA, or somewhere else entirely? Furthermore, if it finds multiple copies of that assembly, how should it choose which one to use?
LoadFrom
has one set of rules, whileLoadFile
has another set of rules. It is hard to imagine many reasons to useLoadFile
, but if you needed to use reflection on different copies of the same assembly, it's there for you.From Suzanne Cook's blog:
See here.
Also see Choosing a Binding Context article on the same blog.
Note: If one assembly is loaded using an 8.3 path, and then from a non-8.3 path, they will be seen as different assemblies, even though they are the same physical DLL.
In my case, I just had to simply delete the ASP application cache located @
C:\Windows\Microsoft.NET\Framework\[asp version]\Temporary ASP.NET Files
. It is rebuilt when the site is first run. Be sure to stop IIS first.Hope this helps someone like it did for me.
According to documentation:
LoadFile(String): Loads the contents of an assembly file given a file path.
LoadFrom(String): Loads an assembly given its file name or path.
one difference that i noticed is:
Assembly.LoadFile - Loads assembly in different AppDomain with limited user rights (diffrence principel). operations like serilization/deserilization could not be performed.
Assembly.LoadFrom- Loads assembly in same AppDomain with same user rights (same principel).