AppDomain.TypeResolve イベント
アセンブリ: mscorlib (mscorlib.dll 内)

Dim instance As AppDomain Dim handler As ResolveEventHandler AddHandler instance.TypeResolve, handler
public: virtual event ResolveEventHandler^ TypeResolve { void add (ResolveEventHandler^ value) sealed; void remove (ResolveEventHandler^ value) sealed; }

TypeResolve イベントは、共通言語ランタイムが要求された型を作成できるアセンブリを判別できなかったときに発生します。このイベントは、型が動的アセンブリで定義されている場合、または動的アセンブリでは定義されていないが、ランタイムが型を定義しているアセンブリを判別できない場合に、発生することがあります。後者は、Type.GetType をアセンブリ名で限定されていない型の名前で呼び出したときに発生することがあります。
このイベントの ResolveEventHandler で、型の検索と作成を試行できます。
ただし、型を特定のアセンブリで見つけることができないことをランタイムが認識している場合は、TypeResolve イベントは発生しません。たとえば、静的アセンブリへ動的に型を追加できないことをランタイムが認識しているという理由で静的アセンブリで型を見つけることができない場合、このイベントは発生しません。
このイベントのイベント ハンドラを登録するには、適切なアクセス許可が必要です。アクセス許可がないと、SecurityException がスローされます。

このコード例を実行するには、アセンブリの完全限定名を指定する必要があります。アセンブリの完全限定名を取得する方法については、「アセンブリ名」を参照してください。
Option Strict On Option Explicit On Imports System Imports System.Reflection Imports System.Reflection.Emit Module Test ' For this code example, the following information needs to be ' available to both Main and the HandleTypeResolve event ' handler: Private ab As AssemblyBuilder Private moduleName As String Sub Main() Dim currDom As AppDomain = AppDomain.CurrentDomain ' Create a dynamic assembly with one module, to be saved to ' disk (AssemblyBuilderAccess.Save). ' Dim aName As AssemblyName = new AssemblyName() aName.Name = "Transient" moduleName = aName.Name + ".dll" ab = currDom.DefineDynamicAssembly(aName, _ AssemblyBuilderAccess.Save) Dim mb As ModuleBuilder = _ ab.DefineDynamicModule(aName.Name, moduleName) ' The dynamic assembly has just one dummy type, to demonstrate ' type resolution. Dim tb As TypeBuilder = mb.DefineType("Example") tb.CreateType() ' First, try to load the type without saving the dynamic ' assembly and without hooking up the TypeResolve event. The ' type cannot be loaded. Try Dim temp As Type = Type.GetType("Example", true) Console.WriteLine("Loaded type {0}.", temp) Catch ex As TypeLoadException Console.WriteLine("Loader could not resolve the type.") End Try ' Hook up the TypeResolve event. ' AddHandler currDom.TypeResolve, AddressOf HandleTypeResolve ' Now try to load the type again. The TypeResolve event is ' raised, the dynamic assembly is saved, and the dummy type is ' loaded successfully. Display it to the console, and create ' an instance. Dim t As Type = Type.GetType("Example", true) Console.WriteLine("Loaded type ""{0}"".", t) Dim o As Object = Activator.CreateInstance(t) End Sub Private Function HandleTypeResolve(ByVal sender As Object, _ ByVal e As ResolveEventArgs) As [Assembly] Console.WriteLine("TypeResolve event handler.") ' Save the dynamic assembly, and then load it using its ' display name. Return the loaded assembly. ' ab.Save(moduleName) Return [Assembly].Load(ab.FullName) End Function End Module ' This code example produces the following output: ' 'Loader could not resolve the type. 'TypeResolve event handler. 'Loaded type "Example". '
using System; using System.Reflection; using System.Reflection.Emit; class Test { // For this code example, the following information needs to be // available to both Main and the HandleTypeResolve event // handler: private static AssemblyBuilder ab; private static string moduleName; public static void Main() { AppDomain currDom = AppDomain.CurrentDomain; // Create a dynamic assembly with one module, to be saved to // disk (AssemblyBuilderAccess.Save). // AssemblyName aName = new AssemblyName(); aName.Name = "Transient"; moduleName = aName.Name + ".dll"; ab = currDom.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Save); ModuleBuilder mb = ab.DefineDynamicModule(aName.Name, moduleName); // The dynamic assembly has just one dummy type, to demonstrate // type resolution. TypeBuilder tb = mb.DefineType("Example"); tb.CreateType(); // First, try to load the type without saving the dynamic // assembly and without hooking up the TypeResolve event. The // type cannot be loaded. try { Type temp = Type.GetType("Example", true); Console.WriteLine("Loaded type {0}.", temp); } catch (TypeLoadException) { Console.WriteLine("Loader could not resolve the type."); } // Hook up the TypeResolve event. // currDom.TypeResolve += new ResolveEventHandler(HandleTypeResolve); // Now try to load the type again. The TypeResolve event is // raised, the dynamic assembly is saved, and the dummy type is // loaded successfully. Display it to the console, and create // an instance. Type t = Type.GetType("Example", true); Console.WriteLine("Loaded type \"{0}\".", t); Object o = Activator.CreateInstance(t); } static Assembly HandleTypeResolve(object sender, ResolveEventArgs args) { Console.WriteLine("TypeResolve event handler."); // Save the dynamic assembly, and then load it using its // display name. Return the loaded assembly. // ab.Save(moduleName); return Assembly.Load(ab.FullName); } } /* This code example produces the following output: Loader could not resolve the type. TypeResolve event handler. Loaded type "Example". */
#using <System.dll> #using <System.Windows.Forms.dll> #using <System.Drawing.dll> using namespace System; using namespace System::Reflection; using namespace System::Reflection::Emit; ref class Test { private: static Assembly^ HandleTypeResolve(Object^ sender, ResolveEventArgs^ args) { Console::WriteLine("TypeResolve event handler."); // Save the dynamic assembly, and then load it using its // display name. Return the loaded assembly. // ab->Save(moduleName); return Assembly::Load(ab->FullName); } // For this code example, the following information needs to be // available to both Demo and the HandleTypeResolve event // handler: static AssemblyBuilder^ ab; static String^ moduleName; public: static void Demo() { AppDomain^ currDom = AppDomain::CurrentDomain; // Create a dynamic assembly with one module, to be saved to // disk (AssemblyBuilderAccess::Save). // AssemblyName^ aName = gcnew AssemblyName(); aName->Name = "Transient"; moduleName = aName->Name + ".dll"; ab = currDom->DefineDynamicAssembly(aName, AssemblyBuilderAccess::Save); ModuleBuilder^ mb = ab->DefineDynamicModule(aName->Name, moduleName); // The dynamic assembly has just one dummy type, to demonstrate // type resolution. TypeBuilder^ tb = mb->DefineType("Example"); tb->CreateType(); // First, try to load the type without saving the dynamic // assembly and without hooking up the TypeResolve event. The // type cannot be loaded. try { Type^ temp = Type::GetType("Example", true); Console::WriteLine("Loaded type {0}.", temp); } catch (TypeLoadException^) { Console::WriteLine("Loader could not resolve the type."); } // Hook up the TypeResolve event. // currDom->TypeResolve += gcnew ResolveEventHandler(HandleTypeResolve); // Now try to load the type again. The TypeResolve event is // raised, the dynamic assembly is saved, and the dummy type is // loaded successfully. Display it to the console, and create // an instance. Type^ t = Type::GetType("Example", true); Console::WriteLine("Loaded type \"{0}\".", t); Object^ o = Activator::CreateInstance(t); } }; void main() { Test::Demo(); } /* This code example produces the following output: Loader could not resolve the type. TypeResolve event handler. Loaded type "Example". */


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


_AppDomain.TypeResolve イベント
アセンブリ: mscorlib (mscorlib.dll 内)

Event TypeResolve As ResolveEventHandler
Dim instance As _AppDomain Dim handler As ResolveEventHandler AddHandler instance.TypeResolve, handler
event ResolveEventHandler^ TypeResolve { void add (ResolveEventHandler^ value); void remove (ResolveEventHandler^ value); }


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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

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