ObjectHandle.Unwrap Method

Definition

Returns the wrapped object.

C#
public object? Unwrap();
C#
public object Unwrap();

Returns

The wrapped object.

Implements

Examples

The following code example demonstrates how to activate an object in another AppDomain, retrieve a proxy to it with the Unwrap method, and use the proxy to access the remote object.

C#
// Creates an instance of MyType defined in the assembly called ObjectHandleAssembly.
ObjectHandle obj = domain.CreateInstance("ObjectHandleAssembly", "MyType");

// Unwrapps the proxy to the MyType object created in the other AppDomain.
MyType testObj = (MyType)obj.Unwrap();

if(RemotingServices.IsTransparentProxy(testObj))
   Console.WriteLine("The unwrapped object is a proxy.");
else
   Console.WriteLine("The unwrapped object is not a proxy!");

Console.WriteLine("");
Console.Write("Calling a method on the object located in an AppDomain with the hash code ");
Console.WriteLine(testObj.GetAppDomainHashCode());

Notes to Callers

A ObjectHandle is a remoted MarshalByRefObject that is tracked by the remoting lifetime service. A call to the current method can fail if the lifetime lease on the ObjectHandle expires.

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1