Export (0) Print
Expand All

AssemblyName.GetAssemblyName Method

Gets the AssemblyName for a given file.

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

public static AssemblyName GetAssemblyName(
	string assemblyFile
)

Parameters

assemblyFile
Type: System.String

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

Return Value

Type: System.Reflection.AssemblyName
An object that represents the given assembly file.

ExceptionCondition
ArgumentNullException

assemblyFile is null.

ArgumentException

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

FileNotFoundException

assemblyFile is not found.

SecurityException

The caller does not have path discovery permission.

BadImageFormatException

assemblyFile is not a valid assembly.

FileLoadException

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 example gets the AssemblyName for an assembly on disk. It will not run unless you replace the string "MyAssembly.exe" with the file name of an assembly (including the path, if necessary) on your hard disk. Alternatively, you can compile this 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");
      Console.WriteLine(myAssemblyName.ToString());
   }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft