Monday, 15 July 2013

c# - Activator.CreateInstance() overloads have different return types -



c# - Activator.CreateInstance() overloads have different return types -

i'm using activator.createinstance build object in project. i've noted depending on overload of createinstance call, either object requested or objecthandle.

why this? seems counterintuitive me.

public static object createinstance( type type ) public static objecthandle createinstance( string assemblyname, string typename )

taked here , here

in case of

public static object createinstance( type type )

it possible instantiating object not marshalbyrefobject means instead of proxy real object.

but in case of

public static objecthandle createinstance( string assemblyname, string typename )

it possible, object beingness created either getting instantiated within active .net execution context or possible assembly's type configured hook remote object via underlying proxy returned unwrap() method of objecthandle, remote object created in appdomain. appdomain exist within same process, different process on same machine or remote process on different machine using .net remoting.

another difference is, proxy object returned objecthandle.unwrap() may have lease time. if expired method phone call on proxy object fail! whereas createinstance(type) method's returned object real object instead of proxy.

so, both methods different.

c# .net reflection

No comments:

Post a Comment