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

返回

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

例外

assemblyFilenull

assemblyFile 无效,如包含无效区域性的程序集。

assemblyFile 未找到。

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

assemblyFile 不是有效的程序集。

一个程序集或模块用两个不同的证据集加载了两次。

示例

以下示例获取 AssemblyName 磁盘上程序集的 。 除非将字符串“MyAssembly.exe”替换为程序集 (包含路径的文件名(如有必要,) 硬盘上),否则它不会运行。 或者,可以将此示例编译为“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

注解

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

适用于