AssemblyName.GetAssemblyName(String) 方法

定義

取得指定檔案的 AssemblyNameGets the AssemblyName for a given file.

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

參數

assemblyFile
String

要傳回其 AssemblyName 之組件的路徑。The path for the assembly whose AssemblyName is to be returned.

傳回

表示指定之組件檔的物件。An object that represents the given assembly file.

例外狀況

assemblyFilenullassemblyFile is null.

assemblyFile 無效,如具有無效文化特性的組件。assemblyFile is invalid, such as an assembly with an invalid culture.

找不到 assemblyFileassemblyFile is not found.

呼叫端沒有路徑探索權限。The caller does not have path discovery permission.

assemblyFile 不是有效的組件。assemblyFile is not a valid assembly.

已使用兩組不同的辨識項載入組件或模組兩次。An assembly or module was loaded twice with two different sets of evidence.

範例

下列範例會取得磁片上元件的 AssemblyNameThe following example gets the AssemblyName for an assembly on disk. 除非您將字串 "MyAssembly" 取代為元件的檔案名(如有必要,請在硬碟上包含路徑),否則不會執行此動作。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. 或者,您可以將此範例編譯為 "MyAssembly"。Alternatively, you can compile this example as "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

備註

只有在檔案包含組件資訊清單時,才會有作用。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.

安全性

FileIOPermission
以存取路徑中的資訊。for access to information in the path. 關聯的列舉型別:PathDiscoveryAssociated enumeration: PathDiscovery.

適用於