1

We have twice the same dlls in separate folders.

When we load the second dlls using

Assembly.ReflectionOnlyLoadFrom(assemblyPath)

we get an error :

"API restriction: The assembly 'file.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain."

Which is understandable but when we do :

Assembly.LoadFrom(assemblyPath);

it works fine.

Why ? what whould change using the "ReflectionOnly" method.

In our case the only usage would be to use the GetName() method on the result, and I guess that in this case, the result should be strictly the same ?

Thanks

azerty
  • 698
  • 7
  • 28
  • possible duplicate - http://stackoverflow.com/questions/305835/c-sharp-assembly-load-vs-assembly-reflectiononlyload – Amit Kumar Ghosh Aug 17 '16 at 10:25
  • @Amit just that a question mentions the same two method names does not mean it is a duplicate. The [question you link to](http://stackoverflow.com/questions/305835/c-sharp-assembly-load-vs-assembly-reflectiononlyload) asks about errors when using `ReflectionOnlyLoadFrom()`. – CodeCaster Aug 17 '16 at 10:32

1 Answers1

1

When you load an assembly for ReflectionOnly, only the metadata gets loaded. This allows you to inspect its types, but not instantiate or execute any of them.

There's also a property indicating whether an assembly was loaded for reflection only.

So per AppDomain, an assembly can be loaded once: either fully, or for reflection only. Given it's already fully loaded, you can't load it again for reflection only.

The call to Assembly.LoadFrom(), even when provided two different paths, will only load the same assembly once, as long as they match in version. See also Side effects of calling Assembly.Load multiple times.

See also: MSDN: How to: Load Assemblies into the Reflection-Only Context.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272