Share via


AssemblyName.GetAssemblyName(String) Metode

Definisi

AssemblyName Mendapatkan untuk file tertentu.

public:
 static System::Reflection::AssemblyName ^ GetAssemblyName(System::String ^ assemblyFile);
public static System.Reflection.AssemblyName GetAssemblyName (string assemblyFile);
static member GetAssemblyName : string -> System.Reflection.AssemblyName
Public Shared Function GetAssemblyName (assemblyFile As String) As AssemblyName

Parameter

assemblyFile
String

Jalur untuk assembly yang AssemblyName akan dikembalikan.

Mengembalikan

Objek yang mewakili file assembly yang diberikan.

Pengecualian

assemblyFileadalah null.

assemblyFile tidak valid, seperti rakitan dengan budaya yang tidak valid.

assemblyFile tidak ditemukan.

Pemanggil tidak memiliki izin penemuan jalur.

assemblyFile bukan rakitan yang valid.

Rakitan atau modul dimuat dua kali dengan dua set bukti yang berbeda.

Contoh

Contoh berikut mendapatkan AssemblyName untuk assembly pada disk. Ini tidak akan berjalan kecuali Anda mengganti string "MyAssembly.exe" dengan nama file assembly (termasuk jalur, jika perlu) pada hard disk Anda. Atau, Anda dapat mengkompilasi contoh ini sebagai "MyAssembly.exe".

#using <system.dll>

using namespace System;
using namespace System::Reflection;
int 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 );
}

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());
   }
}
Imports System.Reflection

Public Class AssemblyName_GetAssemblyName
   
   Public Shared Sub 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.
      '
      Dim myAssemblyName As AssemblyName = AssemblyName.GetAssemblyName("MyAssembly.exe")
      Console.WriteLine(vbCrLf & "Displaying assembly information:" & vbCrLf)
      Console.WriteLine(myAssemblyName.ToString())
   End Sub
End Class

Keterangan

Ini hanya akan berfungsi jika file berisi manifes perakitan. Metode ini menyebabkan file dibuka dan ditutup, tetapi rakitan tidak ditambahkan ke domain ini.

Berlaku untuk