Strange behavior when mixing assembly loading using Assembly.LoadFrom and Assembly.Load
I came across strange behavior when loading assemblies using Assembly.LoadFrom and later with Assembly.Load.
I load the assembly using Assembly.LoadFrom, where the assembly is in a folder that is not a runtime folder.
Later in my test code, when I try to load this assembly again from Assembly.Load, the load fails with System.IO.FileNotFoundException ("Could not load file or assembly ..."), even though the assembly is already loaded . The load does not work with either a strong name or a weak name (the original reason for reloading this assembly is to use a binary file).
However, if the assembly is in the execution folder, later loading will succeed in both cases with a strong name and a weak name. In this case, you can see that two identical assemblies are being loaded from two different places.
A simple example of code that recreates this problem is
Mounting Assembly1 = Assembly.LoadFrom (@ "C: \ a.dll");
// Loading with a strong name is not performed Assembly assembly2 = Assembly.Load (@ "a, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 14986c3f172d1c2c");
// Also loading with a slight error Mounting assembly3 = Assembly.Load (@ "a");
- Any explanation why the CLR ignores an already loaded assembly?
- Any idea how I can solve this problem?
Thanks.
source
share