Hello,
Current software is ArcGIS 10.8.2 on Windows 10, application development with Visual Studio 2022.
I wrote a simple application for a one-time adaptation to a file geodatabase with feature linked annotations, to correct feature and annotation fields and positions. But it fails on IFeatureClass.Update() with the error message 'Objects in this class cannot be updated outside an edit session', although an IWorkspaceEdit is used. It doesn't matter if the fgdb is on a network share or locally stored.
I do not need any graphical interface, so I can't test it with IMap, IMxApplication and IEditor.
Both featureclass and annotationclasses are in a the same featuredataset. I included only the featureclass in the code fragment.
IFeatureWorkspace editableWorkspace;
string workspacePath = "c:\anyfolder\mygeodatabase.gdb";
using (ComReleaser comReleaser = new ComReleaser())
{
object obj = new object();
Type t = null;
comReleaser.ManageLifetime(obj);
t = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
obj = Activator.CreateInstance(t);
IWorkspaceFactory workspaceFactory = obj as FileGDBWorkspaceFactory;
if (workspaceFactory != null)
{
editableWorkspace = workspaceFactory.OpenFromFile(workspacePath, 0) as IFeatureWorkspace;
}
}
IFeatureDataset editableDataset = editableWorkspace.OpenFeatureDataset("mydataset");
IFeatureClass editableFeatureClass;
string featureClassName = "myfeatureclass";
if (editableDataset != null)
{
IEnumDataset enumDataset = editableDataset.Subsets;
enumDataset.Reset();
IDataset currentDataset = enumDataset.Next();
while (currentDataset != null)
{
if (currentDataset is IFeatureClass && currentDataset.Name == featureClassName)
{
editableFeatureClass = currentDataset as IFeatureClass;
break;
}
currentDataset = enumDataset.Next();
}
}
IWorkspaceEdit2 workspaceEdit;
workspaceEdit = editableWorkspace as IWorkspaceEdit2;
workspaceEdit.StartEditing(false);
if (workspaceEdit.IsBeingEdited())
{
workspaceEdit.StartEditOperation();
if (workspaceEdit.IsInEditOperation)
{
IQueryFilter filter = new QueryFilter { WhereClause = "OBJECTID = 1" };
IFeatureCursor cursor = editableFeatureClass.Update(filter, false); // throws error
if (cursor != null)
{
IFeature feature = cursor.NextFeature();
if (feature != null)
{
feature.set_Value(3, "mytext");
feature.Store();
}
}
Marshal.ReleaseComObject(cursor);
workspaceEdit.StopEditOperation();
}
workspaceEdit.StopEditing(true);
}I can read the fgdb in C# and also edit it in ArcMap. Must doing something wrong, but can't see it.
Many thank for helping,
Kind regards,
Pieter