Sometimes you need to know which version of an assembly was loaded by your .NET application. The following code snippet makes it easy:

using System.Reflection;
using System.Windows.Forms;

static public void ShowAssemblyVersion( Type type )
{
Assembly asm = Assembly.GetAssembly( type );
if (asm != null)
{
AssemblyName asmName = asm.GetName();
string text = String.Format(
"Assembly Name={0} Version={1}",
asmName.Name, asmName.Version );
MessageBox.Show( text );
}
}

Then to display the assembly version, simply call the ShowAssemblyVersion method defined above, passing any type that's defined in the assembly. For example, if the class "MyType" is defined in your assembly:

ShowAssemblyVersion( typeof( MyType ) );

Popularity: 15% [?]

Related posts:

  1. Determine if a Loaded .NET Assembly is Signed
  2. .NET Assembly FAQ – Part 2 – Attributes
  3. Determine the .NET Versions on which an Application is Compiled and Running
  4. .NET Assembly FAQ – Part 1
  5. .NET Assembly FAQ – Part 4 – Global Assembly Cache