Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês

Método Assembly.Load (String)

 

Carrega um conjunto de módulos (assembly) dada a forma completa de seu nome.

Namespace:   System.Reflection
Assembly:  mscorlib (em mscorlib.dll)

public static Assembly Load(
	string assemblyString
)

Parâmetros

assemblyString
Type: System.String

O formato longo do nome do assembly.

Valor Retornado

Type: System.Reflection.Assembly

O assembly carregado.

Exception Condition
ArgumentNullException

assemblyString é null.

ArgumentException

assemblyString é uma cadeia de comprimento zero.

FileNotFoundException

assemblyString não foi encontrado.

FileLoadException

Não foi possível carregar um arquivo que foi encontrado.

BadImageFormatException

assemblyString não é um assembly válido.

-ou-

A versão 2,0 ou posterior do Common Language Runtime está carregada e assemblyString foi compilada com uma versão posterior.

The long form of an assembly name consists of its simple name (such as "System" for the System.dll assembly) along with its version, culture, public key token, and optionally its processor architecture. It corresponds to the assembly's P:System.Reflection.Assembly.FullName property. The following example illustrates the use of a long name to load the System.dll assembly for the .NET Framework 4.

using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      string longName = "system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
      Assembly assem = Assembly.Load(longName);
      if (assem == null)
         Console.WriteLine("Unable to load assembly...");
      else
         Console.WriteLine(assem.FullName);
   }
}
// The example displays the following output:
//        system, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

FileLoadException is thrown if assemblyString specifies the full assembly name, and the first assembly that matches the simple name has a different version, culture, or public key token. The loader does not continue probing for other assemblies that match the simple name.

Whether certain permissions are granted or not granted to an assembly is based on evidence. The rules for assembly and security evidence merging are as follows:

  • When you use a M:System.Reflection.Assembly.Load(System.String) method with no T:System.Security.Policy.Evidence parameter, the assembly is loaded with the evidence that the loader supplies.

  • When you use a M:System.Reflection.Assembly.Load(System.String) method with an T:System.Security.Policy.Evidence parameter, pieces of evidence are merged. Pieces of evidence supplied as an argument to the M:System.Reflection.Assembly.Load(System.String) method supersede pieces of evidence supplied by the loader.

  • When you use a M:System.Reflection.Assembly.Load(System.String) method overload with a Byte[] parameter to load a common object file format (COFF) image, evidence is inherited from the calling assembly. This applies to the .NET Framework version 1.1 Service Pack 1 (SP1) and subsequent releases.

    System_CAPS_noteObservação

    In the .NET Framework version 1.0 and in version 1.1 without SP1, when you use a M:System.Reflection.Assembly.Load(System.String) method overload with a Byte[] parameter to load a COFF image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.

  • When you use a M:System.Reflection.Assembly.Load(System.String) method with a Byte[] parameter and T:System.Security.Policy.Evidence to load a COFF image, only the supplied evidence is used. Evidence of the calling assembly and evidence of the COFF image is ignored.

Reflecting on C++ executable files might throw a T:System.BadImageFormatException. This is most likely caused by the C++ compiler stripping the relocation addresses or the .reloc section from your executable file. To preserve the .reloc address for your C++ executable file, specify /fixed:no when you are linking.

In the .NET Framework version 2.0, processor architecture is added to assembly identity, and can be specified as part of assembly name strings. For example, "ProcessorArchitecture=msil". However, the recommended way to specify an assembly name is to create an T:System.Reflection.AssemblyName object and pass it to an appropriate overload of the Overload:System.Reflection.Assembly.Load method. See P:System.Reflection.AssemblyName.ProcessorArchitecture.

The following example loads an assembly given its fully qualified name, and lists all the types contained in the specified assembly. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [<topic://cpconassemblynames>].

using System;
using System.Reflection;

class Class1
{
    public static void Main()
    {
        // You must supply a valid fully qualified assembly name.            
        Assembly SampleAssembly = Assembly.Load
		    ("SampleAssembly, Version=1.0.2004.0, Culture=neutral, PublicKeyToken=8744b20f8da049e3");
        // Display all the types contained in the specified assembly.
		foreach (Type oType in SampleAssembly.GetTypes()) {
            Console.WriteLine(oType.Name);
        }
    }
}

SecurityPermission

to load an assembly with evidence. Associated enumeration: F:System.Security.Permissions.SecurityPermissionFlag.ControlEvidence

.NET Framework
Disponível desde 1.1
Biblioteca de Classes Portátil
Com suporte no: plataformas portáteis do .NET
Silverlight
Disponível desde 2.0
Windows Phone Silverlight
Disponível desde 7.0
Retornar ao início
Mostrar: