I'm working with ArcObjects edit sessions for the first time and am having some trouble with it. The C# code I am about to discuss is part of an ArcMap 9.3 extension DLL.
My problem is that calls to IFeature.Store inside edit operations seem to simply bypass the edit operation (and edit session) in which they execute.
This is my code:
IFeatureWorkspace workspace = …;
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
if (!workspaceEdit.IsBeingEdited()) return;
// at this point we know that we are inside an edit session.
IFeatureClass featureClass = workspace.OpenFeatureClass(…);
workspaceEdit.StartEditOperation();
try
{
IFeature feature;
IFeatureCursor features = featureClass.Search(null, false);
// (ESRI recommends search cursors inside ArcMap, even when updating inside edit sessions.)
while ((feature = features.NextFeature()) != null)
{
feature.set_Value(…); // only as an example; assume that the feature is modified somehow.
feature.Store();
}
workspaceEdit.StopEditOperation();
}
catch
{
workspaceEdit.AbortEditOperation();
throw;
}
As you can see, the edit operation in this code modifies all features in some feature class.
Let's say that after a few successful feature updates, one update throws an exception. The exception handler in the above code would then call workspaceEdit.AbordEditOperation();. As I understand it, this should rollback all modifications done inside the edit operation (including the previous, successful feature updates). I am however observing that the effects of feature.Store(); never get rolled back.
I have also tried this with IEditor.StartOperation/.StopOperation/.AbortOperation instead of the IWorkspaceEdit methods, but that doesn't change the observed behaviour.
Can anyone explain to me what I am doing wrong? How can I rollback the effects of IFeature.Store in an edit session?