Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

AssemblyName.GetAssemblyName Method

Gets the AssemblyName for a given file.

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

Parameters

assemblyFile
The assembly file for which to get the AssemblyName.

Return Value

An AssemblyName object representing the given file.

Exceptions

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.

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.

Example

[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)
      Console.WriteLine(myAssemblyName.ToString())
   End Sub 'Main 
End Class 'AssemblyName_GetAssemblyName 

[C#] 

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");
      Console.WriteLine(myAssemblyName.ToString());
   }
}

[C++] 

#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");
   Console::WriteLine(myAssemblyName);
}

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

Requirements

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.