AssemblyName.GetAssemblyName(String) Method

Definition

Gets the AssemblyName for a given file.

C#
public static System.Reflection.AssemblyName GetAssemblyName(string assemblyFile);

Parameters

assemblyFile
String

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

Returns

An object that represents the given assembly file.

Exceptions

assemblyFile is null.

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.

Examples

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".

C#

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());
   }
}

Remarks

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.

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1