Overloads Activator.CreateInstance () have different return types

I use Activator.CreateInstanceto create an object in my project. I noticed that depending on what kind of overload CreateInstanceyou are causing, you get either the requested object or ObjectHandle .

Why is this? it seems to me very controversial.

public static Object CreateInstance( Type type )

public static ObjectHandle CreateInstance( string assemblyName, string typeName )

recorded from here and here

+4
source share
1 answer

When

public static Object CreateInstance( Type type )

it’s possible that you are creating an instance of an object that is not a MarshalByRefObject, which means that instead of a proxy, it is a real object.

But in case

public static ObjectHandle CreateInstance( string assemblyName, string typeName )

, .net, , , Unwrap() ObjectHandle, AppDomain. AppDomain , .NET Remoting.

, -, ObjectHandle.Unwrap(), . , - ! CreateInstance(Type) - .

, .

+1

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


All Articles