AppDomain.Load メソッド (AssemblyName)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As AppDomain Dim assemblyRef As AssemblyName Dim returnValue As Assembly returnValue = instance.Load(assemblyRef)
戻り値
読み込み済みのアセンブリ。


このメソッドは、現在のアプリケーション ドメインにアセンブリを読み込むためだけに使用してください。このメソッドは、静的な Load メソッドを呼び出すことができない呼び出し元との相互運用性を確保するために定義されています。
現在のアプリケーション ドメインではない対象のアプリケーション ドメインで Load を呼び出そうとすると、対象のアプリケーション ドメインにアセンブリが正常に読み込まれます。Assembly は MarshalByRefObject ではないため、読み込まれたアセンブリに対する Assembly をこのメソッドで現在のアプリケーション ドメインに戻そうとした場合、共通言語ランタイムはアセンブリを現在のアプリケーション ドメインに読み込もうとしますが、結果的には読み込みに失敗することがあります。現在のアプリケーション ドメインと、最初にアセンブリが読み込まれたアプリケーション ドメインのパスの設定が異なる場合には、それぞれのアプリケーション ドメインに読み込まれたアセンブリは異なる場合があります。
![]() |
---|
AssemblyName.Name プロパティおよび AssemblyName.CodeBase プロパティの両方が設定された場合、アセンブリの初回読み込み時に、Assembly.FullName プロパティが返す表示名 (バージョン、カルチャなど) が使用されます。ファイルが見つからなかった場合、CodeBase プロパティを使用してアセンブリが検索されます。CodeBase を使用してアセンブリが見つかった場合、表示名とアセンブリが比較されます。比較結果が一致しない場合、FileLoadException がスローされます。 |


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド (String, Evidence)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As AppDomain Dim assemblyString As String Dim assemblySecurity As Evidence Dim returnValue As Assembly returnValue = instance.Load(assemblyString, assemblySecurity)
戻り値
読み込み済みのアセンブリ。



- SecurityPermission (証拠が指定されたアセンブリを読み込むために必要なアクセス許可)。SecurityPermissionFlag.ControlEvidence (関連する列挙体)
- FileIOPermission (ファイルまたはディレクトリから読み取るためのアクセス許可、またはパス自体の情報に対するアクセス許可)。FileIOPermissionAccess.Read、FileIOPermissionAccess.PathDiscovery (関連する列挙体)
- WebPermission ("file://"、"\\UNC\dir\"、"c:\" の形式以外のパスを読み取るために必要なアクセス許可)。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド (Byte[])
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As AppDomain Dim rawAssembly As Byte() Dim returnValue As Assembly returnValue = instance.Load(rawAssembly)
戻り値
読み込み済みのアセンブリ。



このコード例を実行するには、アセンブリの完全限定名を指定する必要があります。アセンブリの完全限定名を取得する方法については、「アセンブリ名」を参照してください。
Imports System 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 'Main 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 'InstantiateMyType ' 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)) 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 'EmitAssembly End Module 'Test
using System; using System.IO; using System.Reflection; using System.Reflection.Emit; class Test { 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"); } }
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! }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド (String)
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As AppDomain Dim assemblyString As String Dim returnValue As Assembly returnValue = instance.Load(assemblyString)
戻り値
読み込み済みのアセンブリ。




Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド (Byte[], Byte[])
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As AppDomain Dim rawAssembly As Byte() Dim rawSymbolStore As Byte() Dim returnValue As Assembly returnValue = instance.Load(rawAssembly, rawSymbolStore)
public: virtual Assembly^ Load ( array<unsigned char>^ rawAssembly, array<unsigned char>^ rawSymbolStore ) sealed
戻り値
読み込み済みのアセンブリ。



このコード例を実行するには、アセンブリの完全限定名を指定する必要があります。アセンブリの完全限定名を取得する方法については、「アセンブリ名」を参照してください。
Imports System 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 'Main 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 'InstantiateMyType ' 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)) 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 'EmitAssembly End Module 'Test
using System; using System.IO; using System.Reflection; using System.Reflection.Emit; class Test { 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"); } }
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! }


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド (Byte[], Byte[], Evidence)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function Load ( _ rawAssembly As Byte(), _ rawSymbolStore As Byte(), _ securityEvidence As Evidence _ ) As Assembly
Dim instance As AppDomain Dim rawAssembly As Byte() Dim rawSymbolStore As Byte() Dim securityEvidence As Evidence Dim returnValue As Assembly returnValue = instance.Load(rawAssembly, rawSymbolStore, securityEvidence)
public: virtual Assembly^ Load ( array<unsigned char>^ rawAssembly, array<unsigned char>^ rawSymbolStore, Evidence^ securityEvidence ) sealed
public final function Load ( rawAssembly : byte[], rawSymbolStore : byte[], securityEvidence : Evidence ) : Assembly
戻り値
読み込み済みのアセンブリ。



このコード例を実行するには、アセンブリの完全限定名を指定する必要があります。アセンブリの完全限定名を取得する方法については、「アセンブリ名」を参照してください。
Imports System 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 'Main 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 'InstantiateMyType ' 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)) 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 'EmitAssembly End Module 'Test
using System; using System.IO; using System.Reflection; using System.Reflection.Emit; class Test { 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"); } }
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! }

- SecurityPermission (証拠を提供するために必要なアクセス許可)。SecurityPermissionFlag.ControlEvidence (関連する列挙体)
- FileIOPermission (ファイルまたはディレクトリから読み取るためのアクセス許可、またはパス自体の情報に対するアクセス許可)。FileIOPermissionAccess.Read、FileIOPermissionAccess.PathDiscovery (関連する列挙体)
- WebPermission ("file://"、"\\UNC\dir\"、"c:\" の形式以外のパスを読み取るために必要なアクセス許可)。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド (AssemblyName, Evidence)
アセンブリ: mscorlib (mscorlib.dll 内)

Public Function Load ( _ assemblyRef As AssemblyName, _ assemblySecurity As Evidence _ ) As Assembly
Dim instance As AppDomain Dim assemblyRef As AssemblyName Dim assemblySecurity As Evidence Dim returnValue As Assembly returnValue = instance.Load(assemblyRef, assemblySecurity)
戻り値
読み込み済みのアセンブリ。



- FileIOPermission (ファイルまたはディレクトリから読み取るためのアクセス許可、またはパス自体の情報に対するアクセス許可)。FileIOPermissionAccess.Read、FileIOPermissionAccess.PathDiscovery (関連する列挙体)
- SecurityPermission (証拠が指定されたアセンブリを読み込むために必要なアクセス許可)。SecurityPermissionFlag.ControlEvidence (関連する列挙体)
- WebPermission ("file://"、"\\UNC\dir\"、"c:\" の形式以外のパスを読み取るために必要なアクセス許可)。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AppDomain.Load メソッド

名前 | 説明 |
---|---|
AppDomain.Load (AssemblyName) | AssemblyName を指定して、Assembly を読み込みます。 |
AppDomain.Load (Byte[]) | 生成された Assembly を含む COFF (Common Object File Format) ベースのイメージを使用して、Assembly を読み込みます。 |
AppDomain.Load (String) | 表示名を指定して Assembly を読み込みます。 |
AppDomain.Load (AssemblyName, Evidence) | AssemblyName を指定して、Assembly を読み込みます。 |
AppDomain.Load (Byte[], Byte[]) | 生成された Assembly を含む COFF (Common Object File Format) ベースのイメージを使用して、Assembly を読み込みます。Assembly のシンボルを表す生バイトも読み込まれます。 |
AppDomain.Load (String, Evidence) | 表示名を指定して Assembly を読み込みます。 |
AppDomain.Load (Byte[], Byte[], Evidence) | 生成された Assembly を含む COFF (Common Object File Format) ベースのイメージを使用して、Assembly を読み込みます。Assembly のシンボルを表す生バイトも読み込まれます。 |

_AppDomain.Load メソッド

名前 | 説明 |
---|---|
_AppDomain.Load (AssemblyName) | COM オブジェクトに、AppDomain.Load(AssemblyName) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |
_AppDomain.Load (Byte[]) | COM オブジェクトに、AppDomain.Load(Byte[]) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |
_AppDomain.Load (String) | COM オブジェクトに、AppDomain.Load(String) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |
_AppDomain.Load (AssemblyName, Evidence) | COM オブジェクトに、AppDomain.Load(AssemblyName,Evidence) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |
_AppDomain.Load (Byte[], Byte[]) | COM オブジェクトに、AppDomain.Load(Byte[],Byte[]) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |
_AppDomain.Load (String, Evidence) | COM オブジェクトに、AppDomain.Load(String,Evidence) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |
_AppDomain.Load (Byte[], Byte[], Evidence) | COM オブジェクトに、AppDomain.Load(Byte[],Byte[],Evidence) メソッド オーバーロードへのバージョンに依存しないアクセスが用意されています。 |

Weblioに収録されているすべての辞書からAppDomain.Loadを検索する場合は、下記のリンクをクリックしてください。

- AppDomain.Loadのページへのリンク