다음을 통해 공유


AppDomain.Load 메서드

정의

이 애플리케이션 도메인에 Assembly 로드합니다.

오버로드

Name Description
Load(Byte[])

내보내Assembly기를 Assembly 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 로드합니다.

Load(AssemblyName)

지정된 해당 을 로드합니다 AssemblyAssemblyName.

Load(String)

지정된 표시 이름을 로드합니다 Assembly .

Load(Byte[], Byte[])

내보내Assembly기를 Assembly 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 로드합니다. 기호 Assembly 를 나타내는 원시 바이트도 로드됩니다.

Load(AssemblyName, Evidence)
사용되지 않음.

지정된 해당 을 로드합니다 AssemblyAssemblyName.

Load(String, Evidence)
사용되지 않음.

지정된 표시 이름을 로드합니다 Assembly .

Load(Byte[], Byte[], Evidence)
사용되지 않음.

내보내Assembly기를 Assembly 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 로드합니다. 기호 Assembly 를 나타내는 원시 바이트도 로드됩니다.

Load(Byte[])

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

내보내Assembly기를 Assembly 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 로드합니다.

public:
 System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly);
public:
 virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
public System.Reflection.Assembly Load(byte[] rawAssembly);
public System.Reflection.Assembly Load(byte[] rawAssembly);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")>]
member this.Load : byte[] -> System.Reflection.Assembly
member this.Load : byte[] -> System.Reflection.Assembly
abstract member Load : byte[] -> System.Reflection.Assembly
override this.Load : byte[] -> System.Reflection.Assembly
Public Function Load (rawAssembly As Byte()) As Assembly

매개 변수

rawAssembly
Byte[]

내보낸 어셈블리를 포함하는 COFF 기반 이미지인 형식 byte 의 배열입니다.

반환

로드된 어셈블리입니다.

구현

특성

예외

rawAssemblynull입니다.

rawAssembly 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

예제

다음 샘플에서는 원시 어셈블리를 로드하는 방법을 보여 줍니다.

이 코드 예제를 실행하려면 정규화된 어셈블리 이름을 제공해야 합니다. 정규화된 어셈블리 이름을 가져오는 방법에 대한 자세한 내용은 어셈블리 이름을 참조하세요.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
void InstantiateMyType( AppDomain^ domain )
{
   try
   {
      
      // You must supply a valid fully qualified assembly name here.
      domain->CreateInstance( "Assembly text name, Version, Culture, PublicKeyToken", "MyType" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}


// Loads the content of a file to a Byte array.
array<Byte>^ loadFile( String^ filename )
{
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   array<Byte>^buffer = gcnew array<Byte>((int)fs->Length);
   fs->Read( buffer, 0, buffer->Length );
   fs->Close();
   return buffer;
}


// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
void EmitAssembly( AppDomain^ domain )
{
   AssemblyName^ assemblyName = gcnew AssemblyName;
   assemblyName->Name = "MyAssembly";
   AssemblyBuilder^ assemblyBuilder = domain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Save );
   ModuleBuilder^ moduleBuilder = assemblyBuilder->DefineDynamicModule( "MyModule", "temp.dll", true );
   TypeBuilder^ typeBuilder = moduleBuilder->DefineType( "MyType", TypeAttributes::Public );
   ConstructorBuilder^ constructorBuilder = typeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, nullptr );
   ILGenerator^ ilGenerator = constructorBuilder->GetILGenerator();
   ilGenerator->EmitWriteLine( "MyType instantiated!" );
   ilGenerator->Emit( OpCodes::Ret );
   typeBuilder->CreateType();
   assemblyBuilder->Save( "temp.dll" );
}

ref class Resolver
{
public:
   static Assembly^ MyResolver( Object^ sender, ResolveEventArgs^ args )
   {
      AppDomain^ domain = dynamic_cast<AppDomain^>(sender);
      
      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly( domain );
      array<Byte>^rawAssembly = loadFile( "temp.dll" );
      array<Byte>^rawSymbolStore = loadFile( "temp.pdb" );
      Assembly^ assembly = domain->Load( rawAssembly, rawSymbolStore );
      return assembly;
   }

};

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   InstantiateMyType( currentDomain ); // Failed!
   currentDomain->AssemblyResolve += gcnew ResolveEventHandler( Resolver::MyResolver );
   InstantiateMyType( currentDomain ); // OK!
}
using System;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;

class LoadRawSnippet {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;

      InstantiateMyType(currentDomain);   // Failed!

      currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);

      InstantiateMyType(currentDomain);   // OK!
   }

   static void InstantiateMyType(AppDomain domain) {
      try {
     // You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }

   // Loads the content of a file to a byte array.
   static byte[] loadFile(string filename) {
      FileStream fs = new FileStream(filename, FileMode.Open);
      byte[] buffer = new byte[(int) fs.Length];
      fs.Read(buffer, 0, buffer.Length);
      fs.Close();

      return buffer;
   }

   static Assembly MyResolver(object sender, ResolveEventArgs args) {
      AppDomain domain = (AppDomain) sender;

      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly(domain);

      byte[] rawAssembly = loadFile("temp.dll");
      byte[] rawSymbolStore = loadFile("temp.pdb");
      Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);

      return assembly;
   }

   // Creates a dynamic assembly with symbol information
   // and saves them to temp.dll and temp.pdb
   static void EmitAssembly(AppDomain domain) {
      AssemblyName assemblyName = new AssemblyName();
      assemblyName.Name = "MyAssembly";

      AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
      ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true);
      TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);

      ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null);
      ILGenerator ilGenerator = constructorBuilder.GetILGenerator();
      ilGenerator.EmitWriteLine("MyType instantiated!");
      ilGenerator.Emit(OpCodes.Ret);

      typeBuilder.CreateType();

      assemblyBuilder.Save("temp.dll");
   }
}
open System
open System.IO
open System.Reflection
open System.Reflection.Emit

let instantiateMyType (domain: AppDomain) =
    try
        // You must supply a valid fully qualified assembly name here.
        domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
        |> ignore  
    with e ->
        printfn $"{e.Message}"

// Loads the content of a file to a byte array.
let loadFile filename =
    use fs = new FileStream(filename, FileMode.Open)
    let buffer = Array.zeroCreate<byte> (int fs.Length)
    fs.Read(buffer, 0, buffer.Length) |> ignore
    fs.Close()
    buffer

// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
let emitAssembly (domain: AppDomain) =
    let assemblyName = AssemblyName()
    assemblyName.Name <- "MyAssembly"

    let assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
    let moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true)
    let typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)

    let constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null)
    let ilGenerator = constructorBuilder.GetILGenerator()
    ilGenerator.EmitWriteLine "MyType instantiated!"
    ilGenerator.Emit OpCodes.Ret

    typeBuilder.CreateType() |> ignore

    assemblyBuilder.Save "temp.dll"

let myResolver (sender: obj) (args: ResolveEventArgs) =
    let domain = sender :?> AppDomain

    // Once the files are generated, this call is
    // actually no longer necessary.
    emitAssembly domain

    let rawAssembly = loadFile "temp.dll"
    let rawSymbolStore = loadFile "temp.pdb"
    domain.Load(rawAssembly, rawSymbolStore)

let currentDomain = AppDomain.CurrentDomain

instantiateMyType currentDomain   // Failed!

currentDomain.add_AssemblyResolve (ResolveEventHandler myResolver)

instantiateMyType currentDomain   // OK!
Imports System.IO
Imports System.Reflection
Imports System.Reflection.Emit

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      InstantiateMyType(currentDomain)      ' Failed!

      AddHandler currentDomain.AssemblyResolve, AddressOf MyResolver
      
      InstantiateMyType(currentDomain)      ' OK!
   End Sub
   
   
   Sub InstantiateMyType(domain As AppDomain)
      Try
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub
   
   
   ' Loads the content of a file to a byte array. 
   Function loadFile(filename As String) As Byte()
      Dim fs As New FileStream(filename, FileMode.Open)
      Dim buffer(CInt(fs.Length - 1)) As Byte
      fs.Read(buffer, 0, buffer.Length)
      fs.Close()
      
      Return buffer
   End Function 'loadFile
   
   
   Function MyResolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
      Dim domain As AppDomain = DirectCast(sender, AppDomain)
      
      ' Once the files are generated, this call is
      ' actually no longer necessary.
      EmitAssembly(domain)
      
      Dim rawAssembly As Byte() = loadFile("temp.dll")
      Dim rawSymbolStore As Byte() = loadFile("temp.pdb")
      Dim myAssembly As System.Reflection.Assembly = domain.Load(rawAssembly, rawSymbolStore)
      
      Return myAssembly
   End Function 'MyResolver
   
   
   ' Creates a dynamic assembly with symbol information
   ' and saves them to temp.dll and temp.pdb
   Sub EmitAssembly(domain As AppDomain)
      Dim assemblyName As New AssemblyName()
      assemblyName.Name = "MyAssembly"
      
      Dim assemblyBuilder As AssemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
      Dim moduleBuilder As ModuleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", True)
      Dim typeBuilder As TypeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)
      
      Dim constructorBuilder As ConstructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Nothing)
      Dim ilGenerator As ILGenerator = constructorBuilder.GetILGenerator()
      ilGenerator.EmitWriteLine("MyType instantiated!")
      ilGenerator.Emit(OpCodes.Ret)
      
      typeBuilder.CreateType()
      
      assemblyBuilder.Save("temp.dll")
   End Sub

End Module 'Test

설명

이 메서드의 모든 오버로드에 공통적인 정보는 메서드 오버로드를 Load(AssemblyName) 참조하세요.

.NET Framework 4부터 이 메서드를 사용하여 로드되는 어셈블리의 신뢰 수준은 애플리케이션 도메인의 신뢰 수준과 동일합니다.

적용 대상

Load(AssemblyName)

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

지정된 해당 을 로드합니다 AssemblyAssemblyName.

public:
 System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public:
 virtual System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef);
public System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef);
member this.Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
abstract member Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
override this.Load : System.Reflection.AssemblyName -> System.Reflection.Assembly
Public Function Load (assemblyRef As AssemblyName) As Assembly

매개 변수

assemblyRef
AssemblyName

로드할 어셈블리를 설명하는 개체입니다.

반환

로드된 어셈블리입니다.

구현

예외

assemblyRefnull입니다.

assemblyRef 찾을 수 없습니다.

assemblyRef 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

설명

이 메서드는 어셈블리를 현재 애플리케이션 도메인에 로드하는 데만 사용해야 합니다. 이 메서드는 정적 Assembly.Load 메서드를 호출할 수 없는 상호 운용성 호출자를 위한 편의성으로 제공됩니다. 어셈블리를 다른 애플리케이션 도메인에 로드하려면 다음과 같은 CreateInstanceAndUnwrap메서드를 사용합니다.

요청된 어셈블리의 버전이 이미 로드된 경우 이 메서드는 다른 버전이 요청된 경우에도 로드된 어셈블리를 반환합니다.

부분 어셈블리 이름을 assemblyRef 제공하는 것은 권장되지 않습니다. 부분 이름은 하나 이상의 문화권, 버전 또는 공개 키 토큰을 생략합니다. 개체 대신 문자열을 사용하는 오버로드의 AssemblyName 경우 "MyAssembly, Version=1.0.0.0"은 부분 이름의 예이며 "MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=18ab3442da84b47"은 전체 이름의 예입니다.) 부분 이름을 사용하면 성능에 부정적인 영향을 줍니다. 또한 부분 어셈블리 이름은 애플리케이션 기본 디렉터리 또는BaseDirectoryAppDomainSetup.ApplicationBase)에 어셈블리의 정확한 복사본이 있는 경우에만 전역 어셈블리 캐시에서 어셈블리를 로드할 수 있습니다.

현재 AppDomain 개체가 애플리케이션 도메인 A을 나타내고 메서드가 Load 애플리케이션 도메인 B에서 호출되면 어셈블리가 두 애플리케이션 도메인에 로드됩니다. 예를 들어 다음 코드는 새 애플리케이션 도메인 ChildDomain 및 코드가 실행되는 애플리케이션 도메인으로 로드 MyAssembly 됩니다.

AppDomain^ ad = AppDomain::CreateDomain("ChildDomain");
ad->Load("MyAssembly");
AppDomain ad = AppDomain.CreateDomain("ChildDomain");
ad.Load("MyAssembly");
let ad = AppDomain.CreateDomain "ChildDomain"
ad.Load "MyAssembly"
Dim ad As AppDomain  = AppDomain.CreateDomain("ChildDomain")
ad.Load("MyAssembly")

어셈블리는 파생MarshalByRefObject되지 않으므로 두 도메인 Assembly 에 로드되므로 메서드의 Load 반환 값을 마샬링할 수 없습니다. 대신 공용 언어 런타임은 호출 애플리케이션 도메인에 어셈블리를 로드하려고 시도합니다. 두 애플리케이션 도메인에 로드되는 어셈블리는 두 애플리케이션 도메인의 경로 설정이 다른 경우 다를 수 있습니다.

메모

속성과 AssemblyName.Name 속성이 모두 AssemblyName.CodeBase 설정된 경우 어셈블리를 로드하려는 첫 번째 시도는 표시 이름(속성에서 반환된 버전, 문화권 등 포함)을 Assembly.FullName 사용합니다. 파일을 찾을 CodeBase 수 없으면 어셈블리를 검색하는 데 속성이 사용됩니다. 어셈블리를 사용하여 CodeBase찾을 경우 표시 이름이 어셈블리와 일치합니다. 일치가 실패하면 a가 FileLoadException throw됩니다.

적용 대상

Load(String)

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

지정된 표시 이름을 로드합니다 Assembly .

public:
 System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public:
 virtual System::Reflection::Assembly ^ Load(System::String ^ assemblyString);
public System.Reflection.Assembly Load(string assemblyString);
member this.Load : string -> System.Reflection.Assembly
abstract member Load : string -> System.Reflection.Assembly
override this.Load : string -> System.Reflection.Assembly
Public Function Load (assemblyString As String) As Assembly

매개 변수

assemblyString
String

어셈블리의 표시 이름입니다. FullName을(를) 참조하세요.

반환

로드된 어셈블리입니다.

구현

예외

assemblyStringnull인 경우

assemblyString 찾을 수 없습니다.

assemblyString 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

설명

이 메서드의 모든 오버로드에 공통적인 정보는 메서드 오버로드를 Load(AssemblyName) 참조하세요.

적용 대상

Load(Byte[], Byte[])

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

내보내Assembly기를 Assembly 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 로드합니다. 기호 Assembly 를 나타내는 원시 바이트도 로드됩니다.

public:
 System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore);
public:
 virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")]
public System.Reflection.Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore);
public System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore);
public System.Reflection.Assembly Load(byte[] rawAssembly, byte[]? rawSymbolStore);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Types and members the loaded assembly depends on might be removed")>]
member this.Load : byte[] * byte[] -> System.Reflection.Assembly
member this.Load : byte[] * byte[] -> System.Reflection.Assembly
abstract member Load : byte[] * byte[] -> System.Reflection.Assembly
override this.Load : byte[] * byte[] -> System.Reflection.Assembly
Public Function Load (rawAssembly As Byte(), rawSymbolStore As Byte()) As Assembly

매개 변수

rawAssembly
Byte[]

내보낸 어셈블리를 포함하는 COFF 기반 이미지인 형식 byte 의 배열입니다.

rawSymbolStore
Byte[]

어셈블리의 기호를 나타내는 원시 바이트를 포함하는 형식 byte 의 배열입니다.

반환

로드된 어셈블리입니다.

구현

특성

예외

rawAssemblynull입니다.

rawAssembly 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

예제

다음 샘플에서는 원시 어셈블리를 로드하는 방법을 보여 줍니다.

이 코드 예제를 실행하려면 정규화된 어셈블리 이름을 제공해야 합니다. 정규화된 어셈블리 이름을 가져오는 방법에 대한 자세한 내용은 어셈블리 이름을 참조하세요.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Reflection::Emit;
void InstantiateMyType( AppDomain^ domain )
{
   try
   {
      
      // You must supply a valid fully qualified assembly name here.
      domain->CreateInstance( "Assembly text name, Version, Culture, PublicKeyToken", "MyType" );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}


// Loads the content of a file to a Byte array.
array<Byte>^ loadFile( String^ filename )
{
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   array<Byte>^buffer = gcnew array<Byte>((int)fs->Length);
   fs->Read( buffer, 0, buffer->Length );
   fs->Close();
   return buffer;
}


// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
void EmitAssembly( AppDomain^ domain )
{
   AssemblyName^ assemblyName = gcnew AssemblyName;
   assemblyName->Name = "MyAssembly";
   AssemblyBuilder^ assemblyBuilder = domain->DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess::Save );
   ModuleBuilder^ moduleBuilder = assemblyBuilder->DefineDynamicModule( "MyModule", "temp.dll", true );
   TypeBuilder^ typeBuilder = moduleBuilder->DefineType( "MyType", TypeAttributes::Public );
   ConstructorBuilder^ constructorBuilder = typeBuilder->DefineConstructor( MethodAttributes::Public, CallingConventions::Standard, nullptr );
   ILGenerator^ ilGenerator = constructorBuilder->GetILGenerator();
   ilGenerator->EmitWriteLine( "MyType instantiated!" );
   ilGenerator->Emit( OpCodes::Ret );
   typeBuilder->CreateType();
   assemblyBuilder->Save( "temp.dll" );
}

ref class Resolver
{
public:
   static Assembly^ MyResolver( Object^ sender, ResolveEventArgs^ args )
   {
      AppDomain^ domain = dynamic_cast<AppDomain^>(sender);
      
      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly( domain );
      array<Byte>^rawAssembly = loadFile( "temp.dll" );
      array<Byte>^rawSymbolStore = loadFile( "temp.pdb" );
      Assembly^ assembly = domain->Load( rawAssembly, rawSymbolStore );
      return assembly;
   }

};

int main()
{
   AppDomain^ currentDomain = AppDomain::CurrentDomain;
   InstantiateMyType( currentDomain ); // Failed!
   currentDomain->AssemblyResolve += gcnew ResolveEventHandler( Resolver::MyResolver );
   InstantiateMyType( currentDomain ); // OK!
}
using System;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;

class LoadRawSnippet {
   public static void Main() {
      AppDomain currentDomain = AppDomain.CurrentDomain;

      InstantiateMyType(currentDomain);   // Failed!

      currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);

      InstantiateMyType(currentDomain);   // OK!
   }

   static void InstantiateMyType(AppDomain domain) {
      try {
     // You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
      } catch (Exception e) {
         Console.WriteLine(e.Message);
      }
   }

   // Loads the content of a file to a byte array.
   static byte[] loadFile(string filename) {
      FileStream fs = new FileStream(filename, FileMode.Open);
      byte[] buffer = new byte[(int) fs.Length];
      fs.Read(buffer, 0, buffer.Length);
      fs.Close();

      return buffer;
   }

   static Assembly MyResolver(object sender, ResolveEventArgs args) {
      AppDomain domain = (AppDomain) sender;

      // Once the files are generated, this call is
      // actually no longer necessary.
      EmitAssembly(domain);

      byte[] rawAssembly = loadFile("temp.dll");
      byte[] rawSymbolStore = loadFile("temp.pdb");
      Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);

      return assembly;
   }

   // Creates a dynamic assembly with symbol information
   // and saves them to temp.dll and temp.pdb
   static void EmitAssembly(AppDomain domain) {
      AssemblyName assemblyName = new AssemblyName();
      assemblyName.Name = "MyAssembly";

      AssemblyBuilder assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
      ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true);
      TypeBuilder typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public);

      ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null);
      ILGenerator ilGenerator = constructorBuilder.GetILGenerator();
      ilGenerator.EmitWriteLine("MyType instantiated!");
      ilGenerator.Emit(OpCodes.Ret);

      typeBuilder.CreateType();

      assemblyBuilder.Save("temp.dll");
   }
}
open System
open System.IO
open System.Reflection
open System.Reflection.Emit

let instantiateMyType (domain: AppDomain) =
    try
        // You must supply a valid fully qualified assembly name here.
        domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
        |> ignore  
    with e ->
        printfn $"{e.Message}"

// Loads the content of a file to a byte array.
let loadFile filename =
    use fs = new FileStream(filename, FileMode.Open)
    let buffer = Array.zeroCreate<byte> (int fs.Length)
    fs.Read(buffer, 0, buffer.Length) |> ignore
    fs.Close()
    buffer

// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
let emitAssembly (domain: AppDomain) =
    let assemblyName = AssemblyName()
    assemblyName.Name <- "MyAssembly"

    let assemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
    let moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", true)
    let typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)

    let constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, null)
    let ilGenerator = constructorBuilder.GetILGenerator()
    ilGenerator.EmitWriteLine "MyType instantiated!"
    ilGenerator.Emit OpCodes.Ret

    typeBuilder.CreateType() |> ignore

    assemblyBuilder.Save "temp.dll"

let myResolver (sender: obj) (args: ResolveEventArgs) =
    let domain = sender :?> AppDomain

    // Once the files are generated, this call is
    // actually no longer necessary.
    emitAssembly domain

    let rawAssembly = loadFile "temp.dll"
    let rawSymbolStore = loadFile "temp.pdb"
    domain.Load(rawAssembly, rawSymbolStore)

let currentDomain = AppDomain.CurrentDomain

instantiateMyType currentDomain   // Failed!

currentDomain.add_AssemblyResolve (ResolveEventHandler myResolver)

instantiateMyType currentDomain   // OK!
Imports System.IO
Imports System.Reflection
Imports System.Reflection.Emit

Module Test
   
   Sub Main()
      Dim currentDomain As AppDomain = AppDomain.CurrentDomain
      
      InstantiateMyType(currentDomain)      ' Failed!

      AddHandler currentDomain.AssemblyResolve, AddressOf MyResolver
      
      InstantiateMyType(currentDomain)      ' OK!
   End Sub
   
   
   Sub InstantiateMyType(domain As AppDomain)
      Try
     ' You must supply a valid fully qualified assembly name here.
         domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType")
      Catch e As Exception
         Console.WriteLine(e.Message)
      End Try
   End Sub
   
   
   ' Loads the content of a file to a byte array. 
   Function loadFile(filename As String) As Byte()
      Dim fs As New FileStream(filename, FileMode.Open)
      Dim buffer(CInt(fs.Length - 1)) As Byte
      fs.Read(buffer, 0, buffer.Length)
      fs.Close()
      
      Return buffer
   End Function 'loadFile
   
   
   Function MyResolver(sender As Object, args As ResolveEventArgs) As System.Reflection.Assembly
      Dim domain As AppDomain = DirectCast(sender, AppDomain)
      
      ' Once the files are generated, this call is
      ' actually no longer necessary.
      EmitAssembly(domain)
      
      Dim rawAssembly As Byte() = loadFile("temp.dll")
      Dim rawSymbolStore As Byte() = loadFile("temp.pdb")
      Dim myAssembly As System.Reflection.Assembly = domain.Load(rawAssembly, rawSymbolStore)
      
      Return myAssembly
   End Function 'MyResolver
   
   
   ' Creates a dynamic assembly with symbol information
   ' and saves them to temp.dll and temp.pdb
   Sub EmitAssembly(domain As AppDomain)
      Dim assemblyName As New AssemblyName()
      assemblyName.Name = "MyAssembly"
      
      Dim assemblyBuilder As AssemblyBuilder = domain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save)
      Dim moduleBuilder As ModuleBuilder = assemblyBuilder.DefineDynamicModule("MyModule", "temp.dll", True)
      Dim typeBuilder As TypeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public)
      
      Dim constructorBuilder As ConstructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Nothing)
      Dim ilGenerator As ILGenerator = constructorBuilder.GetILGenerator()
      ilGenerator.EmitWriteLine("MyType instantiated!")
      ilGenerator.Emit(OpCodes.Ret)
      
      typeBuilder.CreateType()
      
      assemblyBuilder.Save("temp.dll")
   End Sub

End Module 'Test

설명

이 메서드의 모든 오버로드에 공통적인 정보는 메서드 오버로드를 Load(AssemblyName) 참조하세요.

.NET Framework 4부터 이 메서드를 사용하여 로드되는 어셈블리의 신뢰 수준은 애플리케이션 도메인의 신뢰 수준과 동일합니다.

적용 대상

Load(AssemblyName, Evidence)

주의

Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

지정된 해당 을 로드합니다 AssemblyAssemblyName.

public:
 virtual System::Reflection::Assembly ^ Load(System::Reflection::AssemblyName ^ assemblyRef, System::Security::Policy::Evidence ^ assemblySecurity);
public System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public System.Reflection.Assembly Load(System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity);
abstract member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
abstract member Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : System.Reflection.AssemblyName * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (assemblyRef As AssemblyName, assemblySecurity As Evidence) As Assembly

매개 변수

assemblyRef
AssemblyName

로드할 어셈블리를 설명하는 개체입니다.

assemblySecurity
Evidence

어셈블리를 로드하기 위한 증거입니다.

반환

로드된 어셈블리입니다.

구현

특성

예외

assemblyRefnull인 경우

assemblyRef 찾을 수 없습니다.

assemblyRef 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

설명

이 메서드의 모든 오버로드에 공통적인 정보는 메서드 오버로드를 Load(AssemblyName) 참조하세요.

적용 대상

Load(String, Evidence)

주의

Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

지정된 표시 이름을 로드합니다 Assembly .

public:
 virtual System::Reflection::Assembly ^ Load(System::String ^ assemblyString, System::Security::Policy::Evidence ^ assemblySecurity);
public System.Reflection.Assembly Load(string assemblyString, System.Security.Policy.Evidence assemblySecurity);
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public System.Reflection.Assembly Load(string assemblyString, System.Security.Policy.Evidence assemblySecurity);
abstract member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
abstract member Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : string * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (assemblyString As String, assemblySecurity As Evidence) As Assembly

매개 변수

assemblyString
String

어셈블리의 표시 이름입니다. FullName을(를) 참조하세요.

assemblySecurity
Evidence

어셈블리를 로드하기 위한 증거입니다.

반환

로드된 어셈블리입니다.

구현

특성

예외

assemblyStringnull인 경우

assemblyString 찾을 수 없습니다.

assemblyString 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

설명

이 메서드의 모든 오버로드에 공통적인 정보는 메서드 오버로드를 Load(AssemblyName) 참조하세요.

적용 대상

Load(Byte[], Byte[], Evidence)

주의

Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkId=155570 for more information.

내보내Assembly기를 Assembly 포함하는 COFF(공용 개체 파일 형식) 기반 이미지를 로드합니다. 기호 Assembly 를 나타내는 원시 바이트도 로드됩니다.

public:
 virtual System::Reflection::Assembly ^ Load(cli::array <System::Byte> ^ rawAssembly, cli::array <System::Byte> ^ rawSymbolStore, System::Security::Policy::Evidence ^ securityEvidence);
public System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")]
public System.Reflection.Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, System.Security.Policy.Evidence securityEvidence);
abstract member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
[<System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of Load which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")>]
abstract member Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
override this.Load : byte[] * byte[] * System.Security.Policy.Evidence -> System.Reflection.Assembly
Public Function Load (rawAssembly As Byte(), rawSymbolStore As Byte(), securityEvidence As Evidence) As Assembly

매개 변수

rawAssembly
Byte[]

내보낸 어셈블리를 포함하는 COFF 기반 이미지인 형식 byte 의 배열입니다.

rawSymbolStore
Byte[]

어셈블리의 기호를 나타내는 원시 바이트를 포함하는 형식 byte 의 배열입니다.

securityEvidence
Evidence

어셈블리를 로드하기 위한 증거입니다.

반환

로드된 어셈블리입니다.

구현

특성

예외

rawAssemblynull입니다.

rawAssembly 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

securityEvidence 가 아닙니다 null. 레거시 CAS 정책을 사용하도록 설정 securityEvidencenull하지 않은 경우 .

설명

이 메서드의 모든 오버로드에 공통적인 정보는 메서드 오버로드를 Load(AssemblyName) 참조하세요.

.NET Framework 4부터 이 메서드를 사용하여 로드되는 어셈블리의 신뢰 수준은 애플리케이션 도메인의 신뢰 수준과 동일합니다.

적용 대상