This documentation is archived and is not being maintained.

AssemblyName.GetAssemblyName Method

Gets the AssemblyName for a given file.

[Visual Basic]
Public Shared Function GetAssemblyName( _
   ByVal assemblyFile As String _
) As AssemblyName
public static AssemblyName GetAssemblyName(
 string assemblyFile
public: static AssemblyName* GetAssemblyName(
 String* assemblyFile
public static function GetAssemblyName(
   assemblyFile : String
) : AssemblyName;


The assembly file for which to get the AssemblyName.

Return Value

An AssemblyName object representing the given file.


Exception Type Condition
ArgumentNullException assemblyFile is a null reference (Nothing in Visual Basic).
ArgumentException assemblyFile is empty.
FileNotFoundException assemblyFile is not found.
SecurityException The caller does not have path discovery permission.
BadImageFormatException assemblyFile is not a valid assembly.


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.


[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.Text.RegularExpressions
Imports Microsoft.VisualBasic

Public Class AssemblyName_GetAssemblyName
   Public Shared Sub Main()

      ' Get the type of 'System.Object'.
      Dim myType As Type = GetType(System.Object)
      ' Get the path of 'System.dll'.
      Dim system As String = Regex.Replace(myType.Assembly.CodeBase, "mscorlib.dll", "System.dll")
      system = Regex.Replace(system, "file:///", "")
      ' Get the assembly information and display to the console.
      Dim myAssemblyName As AssemblyName = AssemblyName.GetAssemblyName(system)
      Console.WriteLine(ControlChars.Cr + "Displaying the assembly information of 'System.dll'" + ControlChars.Cr)
   End Sub 'Main 
End Class 'AssemblyName_GetAssemblyName 


using System;
using System.Reflection;
using System.Text.RegularExpressions;

public class AssemblyName_GetAssemblyName
   public static void Main()

      // Get the type of 'System.Object'.
      Type myType = typeof(System.Object);
      // Get the path of 'System.dll'.
      string system = Regex.Replace(myType.Assembly.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");


#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Text::RegularExpressions;

int main()
   // Get the type of 'System::Object'.
   Type* myType = __typeof(System::Object);

   // Get the path of 'System.dll'.
   String* system = Regex::Replace(myType->Assembly->CodeBase, S"mscorlib.dll", S"System.dll");
   system = Regex::Replace(system, S"file:///", S"");

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

AssemblyName Class | AssemblyName Members | System.Reflection Namespace