I was able to store a serialized IGeometry object into an string field in a datatable from a File Geodatabase.

For performance issues and since the object implements IPersistStream, I want to save the original IGeometry object into a blob field.

So far I'm allowed to cast the geometry to IPersistStream but haven't been able to save it to an ObjectStream

I'm using ArcObjects SDK 10.3.1. Here's the code:

// Insert Geometry to DataTable.
fieldIndex = errorsTable.FindField(m_dataBaseConstants.DataTables.Fields.Geometry);
IObjectStream objectStream = new ObjectStream();
ESRI.ArcGIS.Geometry.IGeometry geom = dataToken.Geometry;
IPersistStream persistStream = (IPersistStream)geom;
// This line throws COMException (0x80004005)
persistStream.Save(objectStream, 0);
errorRow.Value[fieldIndex] = objectStream;

I have no clue why I'm not being able to save. Can you see the problem there?

  • you should start using the 10.x help instead of 9.2. desktop.arcgis.com/en/arcobjects/latest/net/…
    – Brad
    Oct 4, 2017 at 11:39
  • 1
    ...also, I don't see that Geometry implements IPersistStream
    – Brad
    Oct 4, 2017 at 11:41
  • Welcome to GIS SE. Thank you for taking the Tour. Please use the code formatting button ({}) to indent your code to make it legible.
    – Vince
    Oct 4, 2017 at 11:42
  • @Brad Thanks I've updated link references. And you are right, but IPersistStream is being implemented by Polygon, Polyline, Point... which do implement IGeometry, right?
    – Jose
    Oct 4, 2017 at 13:26
  • 1
    Could it be as simple as a bad cast? your persist stream saves to an IStream object but you're trying to save to an IObjectStream, perhaps introduce an IStream variable (call it myStream), persistStream.Save(myStream,0); then objectStream = (IObjectStream)myStream; ... it's worth a shot. What is the exception number (HRESULT)? If it's not a general 999999 there might be some help looking up FDO error constants, or not, sometimes the description is as vague as the original error. Oct 9, 2017 at 21:13

1 Answer 1


I've come with a workaround. @MichaelStimson 's comment about a potential wrong cast helped and made me think to go and just try with another stream object.

IMemoryBlobStream just worked fine for me:

IMemoryBlobStream memoryBlobStream = new MemoryBlobStreamClass();
IGeometry geom = dataToken.Geometry;
IPersistStream persistStream = (IPersistStream)geom;
persistStream.Save(memoryBlobStream, 0);    
errorRow.Value[fieldIndex] = memoryBlobStream;

And then to unblob the persisted object to an IGeometry:

IMemoryBlobStream memoryBlobStream = new MemoryBlobStreamClass();
IPersistStream blob = default(IPersistStream);
memoryBlobStream = blobGeometry as IMemoryBlobStream;

if (geometryType.Equals(esriGeometryType.esriGeometryPoint.ToString()))
    blob = new PointClass();
else if (geometryType.Equals(esriGeometryType.esriGeometryPolyline.ToString()))
    blob = new PolylineClass();
else if (geometryType.Equals(esriGeometryType.esriGeometryPolygon.ToString()))
    blob = new PolygonClass();

IGeometry geometry = blob as IGeometry;

This solves my performance issue when trying to deserialize all the geometries of the table.

  • But I still didn't solve the fact that I haven't been able to save a persisted IGeometry to an IObjectStream.
    – Jose
    Oct 10, 2017 at 9:33
  • 1
    A working compromise is still a victory. I'm glad that my ramblings pointed you in a useful direction, +1 from me and thank you for answering your own question with code. Oct 10, 2017 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.