Getting wrong Version from Assembly using Reflection

Getting wrong Version from Assembly using Reflection

dotpeek does not have any magic here. It's just a very-very confusing name and behavior for Assembly.LoadFile(string path) method. Assembly.LoadFile() does not actually load the assembly at specified path, it would prefer GAC like described here. You could check the actual path of loaded assembly with ProcessExplorer or similar tool.

If you want to load assembly at exact path for reflection purposes, it's better to use Assembly.ReflectionOnlyLoadFrom() method:

Assembly assembly = Assembly.ReflectionOnlyLoadFrom(f);

In this case assembly.GetName().Version should give you the correct assembly version.

原文地址:https://www.cnblogs.com/chucklu/p/14273171.html