I am writing an ArcMap add-in using C# with Visual Studio 2010 and ArcGIS 10.1. I want to add features to a featureclass in an Enterprise Geodatabase (ArcGIS Server 10.1 on SQL Server). This is my code:

var mapLayers = GetAllLayersFromMap();
             if (mapLayers.Count > 0)

                 IWorkspace workspace = ((IDataset)mapLayers[0]).Workspace;
                 IFeatureWorkspace fWorkspace = workspace as IFeatureWorkspace;
                 IWorkspaceEdit workspaceEdit = fWorkspace as IWorkspaceEdit;               


                 ILayer layerPunt = mapLayers[0] as ILayer;
                 IFeatureLayer featureLayer = layerPunt as IFeatureLayer;
                 IFeatureClass punten = featureLayer.FeatureClass;

                 IFeatureBuffer bufferPunten = punten.CreateFeatureBuffer();

                 IFeatureCursor cursorPunten = punten.Insert(true);


When I load a featureclass that has no attachments it works fine. If I create attachments to the same featureclass and try again, it fails. The code crashes on the line where the insert cursor is created: "Objects in this class cannot be edited outside an edit session". When I delete the attachments from the featureclass it works again.

If I start an edit session from ArcMap through the Editor toolbar, I can edit featureclasses with attachments (btw: this proves that the licensing level is ok). So I tried starting the edit session from code through the IEditor interface. It fails on the same line with a COM Exception.

Ideas anyone?


I'm not sure why your code is not working, but here's a sample that does. Supposing you have references to the workspace and the featureclass, do this:

var editWorkspace = workspace as IWorkspaceEdit;
editWorkspace.StartEditing(false); // or true, whatever you want

var cursor = featureclass.Insert(true);

var buffer = featureclass.CreateFeatureBuffer();
buffer.Shape = new PointClass { X = 150000, Y = 455000 }; // not strictly necessary


  • Did you try this code on a featureclass that has attachments Berend? – JsP Mar 11 '15 at 16:58
  • Yes. Same version of ArcGIS and VS too. – Berend Mar 12 '15 at 10:26
  • Does not work for me I'm sorry to say, it is basically the same code. Funny thing though: my code works if I already have an open edit session started from ArcMap... – JsP Mar 12 '15 at 16:02

You'll need to use IMultiuserWorkspaceEdit in combination with IWorkspaceEdit:

IMultiuserWorkspaceEdit muWorkspaceEdit = (IMultiuserWorkspaceEdit)dataset.Workspace;
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace;

muWorkspaceEdit.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); //or esriMultiuserEditSessionMode.esriMESMNonVersioned
  • Isn't this basically the same answer you gave at gis.stackexchange.com/a/156843/664? If so, perhaps we should close this thread as a duplicate of the other. – whuber Aug 3 '15 at 17:40
  • 1
    It is, both questions are basically the same: how to edit an SDE featureclass with attachments (one uses an insert cursor, the other one an update cursor). The solution also works when doing IFeature.Store(). – Julian Gomez Aug 5 '15 at 7:02

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