AssemblyName.GetAssemblyName(String) Método

Definição

Obtém o AssemblyName para determinado arquivo.

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

Parâmetros

assemblyFile
String

O caminho para o assembly cujo AssemblyName deve ser retornado.

Retornos

AssemblyName

Um objeto que representa o arquivo de assembly especificado.

Exceções

assemblyFile é null.

assemblyFile é inválido, como um assembly com uma cultura inválida.

assemblyFile não foi encontrado.

O chamador não tem permissão de descoberta de caminho.

assemblyFile não é um assembly válido.

Um assembly ou módulo foi carregado duas vezes com dois conjuntos de evidências.

Exemplos

O exemplo a seguir obtém o AssemblyName de um assembly em disco. Ele não será executado a menos que você substitua a cadeia de caracteres "MyAssembly.exe" pelo nome do arquivo de um assembly (incluindo o caminho, se necessário) no disco rígido. Como alternativa, você pode compilar este exemplo como "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

Comentários

Isso só funcionará se o arquivo contiver um manifesto do assembly. Esse método faz com que o arquivo seja aberto e fechado, mas o assembly não é adicionado a esse domínio.

Aplica-se a