This document is archived and information here might be outdated.  Recommended version.


IServerContext.CreateObject Method (ArcObjects .NET 10.7 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Server > ESRI.ArcGIS.Server > Interfaces > IS > IServerContext Interface > IServerContext.CreateObject Method
ArcGIS Developer Help

IServerContext.CreateObject Method

Create an object in the server context whose type is specified by the CLSID.

[Visual Basic .NET]
Public Function CreateObject ( _
    ByVal CLSID As String _
) As Object
[C#]
public object CreateObject (
    string CLSID
);
[C++]
HRESULT CreateObject(
  BSTR CLSID
);
[C++]
Parameters
CLSID [in]

CLSID is a parameter of type BSTR

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

Use this method when you need to create an object for use in your application.

Create object will return a proxy to the object that is in the server context. Your application can make use of the proxy as if the object was created locally within its process. If you call a method on the proxy that hands back another object, that object will actually be in the server context and you application will be handed back a proxy to that object. For example, if you get a point from a point collection in the server context using IPointCollection::Point(), the point returned will be in the same context as the point collection.

If you add a point to the point collection using IPointCollection::AddPoint(), the point should be in the same context as the point collection.

Also, you should not directly use objects in a server context with local objects in your application and vice-versa. You can indirectly use objects, or make copies of them. For example, if you have a Point object in a server context, you can get its X, Y properties and use them with local objects, or use them to create a new local point. Don’t directly use the point in the server context as, for example, the geometry of a local graphic element object.

[C#]

Consider the following examples. In each example, assume that objects with Remote in their names are objects in a server context as in:

IPoint pRemotePoint = pServerContext.CreateObject(“esriGeometry.Point”) as IPoint;

while objects with Local in their name are objects are objects created locally as in:

IPoint pLocalPoint = new PointClass();

You can’t set a local object to a remote object:

// this is incorrect
pLocalPoint = pRemotePoint;
// this is also incorrect
pLocalElement.Geometry = pRemotePoint;

Do not set a local object, or a property of a local object, to be an object obtained from a remote object:

// this is incorrect
pLocalPoint = pRemotePointCollection.get_Point(0);

When calling a method on a remote object, don’t pass in local object as parameters:

// this is incorrect
pRemoteWorkspace = pRemoteWorkspaceFactory.Open(pLocalPropertySet,0);

You can get simple data types (double, long, string, etc) that are passed by value from a remote object and use them as properties of a local object as in:

// this is OK
pLocalPoint.X = pRemotePoint.X;


pLocalPoint.Y = pRemotePoint.Y;
[Visual Basic .NET]

Consider the following examples. In each example, assume that objects with Remote in their names are objects in a server context as in:

Dim pRemotePoint as IPoint = pServerContext.CreateObject(“esriGeometry.Point”)

while objects with Local in their name are objects are objects created locally as in:

  Dim pLocalPoint as IPoint = New PointClass

You can’t set a local object to a remote object:

' this is incorrect
Set pLocalPoint = pRemotePoint
' this is also incorrect
Set pLocalElement.Geometry = pRemotePoint

Do not set a local object, or a property of a local object, to be an object obtained from a remote object:

' this is incorrect
Set pLocalPoint = pRemotePointCollection.Point(0)

When calling a method on a remote object, don’t pass in local object as parameters:

' this is incorrect
Set pRemoteWorkspace = pRemoteWorkspaceFactory.Open(pLocalPropertySet,0)

You can get simple data types (double, long, string, etc) that are passed by value from a remote object and use them as properties of a local object as in:

' this is OK
pLocalPoint.X = pRemotePoint.X
pLocalPoint.Y = pRemotePoint.Y

See Also

IServerContext Interface