mercredi 14 mars 2018

Getting wrong version name from Assembly using Reflection

I'm trying to retrieve every assembly version from a huge solution, but I found out when I open the assembly using dotpeek, It shows the real version and I'm able to bindiredirect using this number:

enter image description here

But from reflection the number is completely different using Assembly.ImageRuntimeVersion:

System.Security.Cryptography.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Using Assembly.GetName().Version:

4.0.0.0

I've tried every possible version that I was able to find, with the code below, but none of them brings the right number.

Assembly assembly = Assembly.LoadFile(f);
AssemblyName thisAssemName = assembly.GetName();
Version version = thisAssemName.Version;
FileVersionInfo fileversion = FileVersionInfo.GetVersionInfo(f);

var multipleVersion = fileversion.ProductVersion
    + "|" + version
    + "|" + assembly.ImageRuntimeVersion
    + "|" + assembly;

I don't know the magic behind dotpeek, but It has the right thing. How can I retrieve the same number as the tool?





Aucun commentaire:

Enregistrer un commentaire