AssemblyName.GetAssemblyName Method

Gets the AssemblyName for a given file.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public static AssemblyName GetAssemblyName (
	string assemblyFile
public static AssemblyName GetAssemblyName (
	String assemblyFile
public static function GetAssemblyName (
	assemblyFile : String
) : AssemblyName
Not applicable.



The path for the assembly whose AssemblyName is to be returned.

Return Value

An AssemblyName object representing the given file.

Exception typeCondition


assemblyFile is a null reference (Nothing in Visual Basic).


assemblyFile is invalid, such as an assembly with an invalid culture.


assemblyFile is not found.


The caller does not have path discovery permission.


assemblyFile is not a valid assembly.


An assembly or module was loaded twice with two different sets of evidence.

This will only work if the file contains an assembly manifest. This method causes the file to be opened and closed, but the assembly is not added to this domain.

The following code example gets the AssemblyName for an assembly on disk. It will not run unless you replace the string "MyAssembly.exe" with the filename of an assembly (including the path, if necessary) on your hard disk. Alternatively, you can compile this code example as "MyAssembly.exe".

using System;
using System.Reflection;

public class AssemblyName_GetAssemblyName
   public static void Main()
      // Replace the string "MyAssembly.exe" with the name of an assembly,
      // including a path if necessary. If you do not have another assembly
      // to use, you can use whatever name you give to this assembly.
      AssemblyName myAssemblyName = AssemblyName.GetAssemblyName("MyAssembly.exe");
      Console.WriteLine("\nDisplaying assembly information:\n");

import System.*;
import System.Reflection.*;
import System.Text.RegularExpressions.*;

public class AssemblyNameGetAssemblyName
    public static void main(String[] args)
        // Get the type of 'System.Object'.
        Type myType = Object.class.ToType();

        // Get the path of 'System.dll'.
        String system = Regex.Replace(myType.get_Assembly().get_CodeBase(), 
            "mscorlib.dll", "System.dll");
        system = Regex.Replace(system, "file:///", "");

        // Get the assembly information and display to the console.
        AssemblyName myAssemblyName = AssemblyName.GetAssemblyName(system);
        Console.WriteLine("\nDisplaying the assembly information of "
            + "'System.dll'\n");
    } //main
} //AssemblyNameGetAssemblyName

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions