Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly.LoadFrom returns same Assembly when assembly path and version differs

Imagine this scenario:

var ass1 = Assembly.LoadFrom(@"C:\Work\3.59\assembly1.dll");
var ass2 = Assembly.LoadFrom(@"C:\Work\3.60\assembly1.dll");

Debug.Assert(ass1 != ass2);

The above assert fails. It seems the second call returns the first assembly even if the two assemblies above have different versions and locations.

The assemblies are not stong-named and can't be signed.

Is there a way to force the framework to load them in the same context and domain?

like image 252
Adrian Rus Avatar asked Dec 06 '25 03:12

Adrian Rus


2 Answers

Use Assembly.LoadFile(path) instead.

From MSDN

The LoadFrom method has the following disadvantages. Consider using Load instead.

If an assembly with the same identity is already loaded, LoadFrom returns the loaded assembly even if a different path was specified.

From CLR developer Suzanne Cook's blog:

If the assembly is not strongly-named, then the version is ignored for binding. But, if it is strongly-named, the entire version in the assembly reference needs to match the found assembly.

like image 122
D Stanley Avatar answered Dec 08 '25 16:12

D Stanley


yes, you can use Assembly.LoadFile(). http://blogs.msdn.com/b/suzcook/archive/2003/09/19/loadfile-vs-loadfrom.aspx

like image 30
wiero Avatar answered Dec 08 '25 18:12

wiero