ObjectHandle.Unwrap Method

Returns the wrapped object.

Namespace:  System.Runtime.Remoting
Assembly:  mscorlib (in mscorlib.dll)

public Object Unwrap()

Return Value

Type: System.Object
The wrapped object.

Implements

IObjectHandle.Unwrap()

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.

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.

// 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());
// Creates an instance of MyType defined in the assembly called ObjectHandleAssembly.
ObjectHandle*  obj = domain->CreateInstance(S"ObjectHandleAssembly", S"MyType");

// Unwraps the proxy to the MyType object created in the other AppDomain.
MyType* testObj = dynamic_cast<MyType*>(obj->Unwrap());

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

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft