语言

AssemblyName.GetAssemblyName(String) 方法

定义

获取 AssemblyName 给定文件。

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 程序集的路径。

返回

一个表示给定程序集文件的对象。

例外

assemblyFile 是 null。

assemblyFile 无效,例如具有无效区域性的程序集。

找不到 assemblyFile。

调用方没有路径发现权限。

assemblyFile 不是有效的程序集。

程序集或模块加载了两次,其中包含两组不同的证据。

示例

以下示例获取 AssemblyName 磁盘上的程序集。 除非将字符串“MyAssembly.exe”替换为硬盘上的程序集(包括路径)的文件名,否则它不会运行。 或者,可以将此示例编译为“MyAssembly.exe”。


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

注解

仅当文件包含程序集清单时,此操作才起作用。 此方法会导致文件打开和关闭,但程序集不会添加到此域。

适用于