ProxyAttribute.CreateProxy Method (ObjRef, Type, Object, Context)


Creates an instance of a remoting proxy for a remote object described by the specified ObjRef, and located on the server.

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

public virtual RealProxy CreateProxy(
	ObjRef objRef,
	Type serverType,
	object serverObject,
	Context serverContext


Type: System.Runtime.Remoting.ObjRef

The object reference to the remote object for which to create a proxy.

Type: System.Type

The type of the server where the remote object is located.

Type: System.Object

The server object.

Type: System.Runtime.Remoting.Contexts.Context

The context in which the server object is located.

Return Value

Type: System.Runtime.Remoting.Proxies.RealProxy

The new instance of remoting proxy for the remote object that is described in the specified ObjRef.


The current method is called when a proxy is created out of aObjRef instance that references a class that is marked with the ProxyAttribute attribute. Therefore, the method is used only when a ObjRef is received from a return or parameter on a call, or during the activation of a client-activated object. The ProxyAttribute is not used for well-known object types.

public override RealProxy CreateProxy(ObjRef objRef1,
   Type serverType,
   object serverObject,
   Context serverContext)
   MyProxy myCustomProxy = new MyProxy(serverType);
   if(serverContext != null)
   if((!serverType.IsMarshalByRef)&&(serverContext == null))
      throw new RemotingException("Bad Type for CreateProxy");
   return myCustomProxy;

.NET Framework
Available since 1.1
Return to top