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.

assemblyFile 未找到。assemblyFile 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.

适用于