Is it possible to write C # code that will fire the AppDomain.TypeResolve event?

AppDomain.TypeResolve is mysterious in my eyes. Can someone provide some sample code that fires this event?

Thanks.

+3
source share
3 answers

Type t = Type.GetType("Class1"); will do it.

From MSDN: “The TypeResolve event occurs when the common language runtime cannot determine the assembly that can create the requested type. This can happen if the type is defined in a dynamic assembly or the type is not defined in a dynamic assembly, but the runtime does not know which assembly has a type. The latter situation may occur when Type .. ::. GetType is called with a type name that does not match the assembly name. "

+4

MSDN , :

TypeResolve , , . , , , . Type.GetType , .

:

AppDomain.CurrentDomain.TypeResolve += delegate(object sender, ResolveEventArgs e)
{
    Console.WriteLine("Trying to resolve '{0}'", e.Name);
    return null;
};

Type type = Type.GetType("SomeNamespace.SomeTypeWithoutAssemblyQualifier");
0

AppDomain.TypeResolve , , . , , ( ) GAC.

. :

Type badType = Type.GetType("IDontExist");

, , "" .

0
source

Source: https://habr.com/ru/post/1716812/


All Articles