Environment:
- ArcGIS Pro 3.3
- ArcGIS Pro SDK for .NET
- C# Add-in
- Target data: Shapefile (.shp)
Problem:
In an ArcGIS Pro add-in, I sometimes get the following error when trying to run management.AddSpatialIndex on a shapefile immediately after saving edits:
ERROR 000464: Cannot get exclusive schema lock.
Another application or service is editing or using this data.
(ErrorCode = 464)
This happens even though:
The shapefile is only used inside the same ArcGIS Pro session
All FeatureClass / Row / Cursor objects are properly disposed (using)
No other application is accessing the shapefile
Interestingly, right after this error occurs, I can manually run Add Spatial Index
from the Geoprocessing UI on the same shapefile, and it succeeds without any problem.
Typical flow (simplified)
await Project.Current.SaveEditsAsync();
// Immediately after SaveEditsAsync
await Geoprocessing.ExecuteToolAsync(
"management.AddSpatialIndex",
Geoprocessing.MakeValueArray(shapefilePath)
);
Observations
The error does not always reproduce
It is more likely to happen:
Adding a delay (e.g. Task.Delay(200~400ms)) reduces the frequency,
but does not completely eliminate the issue
File Geodatabase / Enterprise Geodatabase do not show this problem
(only shapefiles)
My understanding
It looks like Project.Current.SaveEditsAsync() returns before all internal
locks related to shapefiles are fully released, and
AddSpatialIndex requires an exclusive schema lock, which sometimes cannot
be obtained immediately after saving edits.
Questions
Is this a known behavior/limitation when using shapefiles with
SaveEditsAsync() + geoprocessing tools?
Is there a recommended or supported way to:
Is using a retry / delay loop the only practical workaround?
Has this behavior changed or improved in newer versions of ArcGIS Pro / SDK?
Any guidance or best practices would be greatly appreciated.