How to check the version of an assembly (dll)?
Asked Answered
C

6

62

I have c# application and when I made a change, I am getting the error message:

An unhandled exception of type 'System.TypeLoadException' occurred in WindowsFormsApplication1.exe

Additional information: Could not load type
'TradeIdeas.TIProData.OddsMakerColumnConfiguration' from assembly 'TIProData, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null’.

This message says the version number of dll (TIProData) is 1.0.0.0. I think there is a later version available. How can I tell the version number of a dll on my machine?

Citation answered 21/4, 2015 at 12:20 Comment(5)
RIght click on the DLL go to Properties > Details. Version 1.0.0.0 Looks like its a development version of the DLLAdaline
That is the file version, not the assembly version @AlexAndersonLouvain
Open csproj file in text editor and find that dll reference, you can change version there, seems there is 1.0.0.0 hard codedCasi
See powershell commands in #3267509Plankton
Does this answer your question? How can I get the assembly file versionPlankton
L
86

You can use JetBrains dotPeek (free), Reflector, ILDASM or ILSpy to get the assembly version.

You usually can find ILDASM in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\ildasm.exe (where v8.1A is the version of the Windows SDK installed).

ILDASM:

ildasm

Reflector:

reflector

Louvain answered 21/4, 2015 at 12:24 Comment(3)
Or Jetbrains dotPeek, which is also free.Johannisberger
Btw it is absurd how hard Microsoft makes something this basicSqueteague
Why is it different from the dll version from windows explorer file details?Hammock
G
9

There is a couple of ways to do it:

  • If you reference the dll in Visual Studio right click it (in ProjectName/References folder) and select "Properties" you have "Version" and "Runtime Version" there.

  • In File Explorer when you right click the dll file and select properties there is a "File Version" and "Product Version" there.

  • Alternatively, investigate it in code:

    Assembly assembly = Assembly.LoadFrom("TestAssembly.dll");
    Version ver = assembly.GetName().Version;
    
Gangrel answered 21/4, 2015 at 13:9 Comment(3)
Caution - the "FileVersion" shown in the properties tab is NOT the same thing as AssemblyVersion which is the id used for binding redirects or assembly loading.Karlakarlan
@Karlakarlan Yes! This has bitten me a few times. A workaround I found is to open the DLL with 7-zip and read the Assembly Version from .rsrc/version.txt . Baffles me why this isn't displayed in the File Properties dialog along with the rest of it.Trichomoniasis
You should remove the middle bullet mentioning File Version and Product Version. It is true, but it implies that these are synonymous with the assembly version because that was the question and you have listed it as one of the "ways to do it".Phuongphycology
T
5

You can use AssemblyName.GetAssemblyName(string path) from a little util app.

Further details here on MSDN.

Thornburg answered 21/4, 2015 at 12:24 Comment(0)
P
4

If you know Class, that belongs to assembly, you can use GetTypeInfo

var runtimeVersion = typeof(MyClass)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyFileVersionAttribute>();

var version = runtimeVersion.Version;

 

The example is for .Net Core from https://developers.de/blogs/damir_dobric/archive/2017/06/27/how-to-deal-with-assembly-version-in-net-core.aspx

Plankton answered 24/10, 2018 at 8:52 Comment(0)
S
3

From Powershell (PSCore): $assembly = [System.Reflection.Assembly]::LoadFrom("$pwd\System.Memory.dll") Besides $assembly.FullName you can pick up any other prop from the object.

Smukler answered 17/2, 2023 at 14:28 Comment(1)
This approach silently gives the wrong answer if a DLL with the same name but in a different folder happens to be loaded already by the PowerShell process. In that case, it gives the assembly version of the already loaded DLL.Caia
D
1

Inspired by JamesLucas' answer, you can create this assversion.fsx script and just run it with dotnet fsi asseversion.fsx ./path/to/your.dll:

if fsi.CommandLineArgs.Length < 2 then
    System.Console.Error.WriteLine("Please supply assembly path")
    exit 1
let arg = fsi.CommandLineArgs.[1]
System.Console.WriteLine(arg)
System.Console.WriteLine(System.Reflection.AssemblyName.GetAssemblyName(arg).ToString())
Danford answered 24/1 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.