Hello,
i try to create a (point)-feature in an existing Layer via ArcGIS Automation.
I can create the Feature but when I call feature.Store() I get an "HRESULT: 0x80010105 (RPC_E_SERVERFAULT)" error.
If I just edit an existing feature that I got from a SearchCursor it works flawlessly.
My application is a WinForms .Net 4.5 programm.
I get a connection to a running ArcMap Instance via IAppRot->IAppRef->IApplication->IDocument.
From the IDocument I get a reference to a specific Layer where I need to add a feature.
After that it is very basic stuff:
IFeatureClass featureClass = ((IFeatureLayer)i_Layer).FeatureClass;
IFeature newObject = featureClass.CreateFeature();
// Assign a geometry to the feature
newObject.Shape = geom;
newObject.Store();
Store allways fails with the RPC_E_SERVERFAULT Exception.
I also tried to create the feature via IFeatureCursor->IFeatureBuffer but then it fails with the same error on
featureCursor.InsertFeature(featureBuffer);
Starting an Edit-Session for this operation has no effect. It just fails later when calling
workspaceEdit.StopEditing(true);
I tried with ArcGIS 10.5 an 10.3 but the results are the same.
Other automation tasks like moving the map, setting layer-visibilities or even editing existing features work perfectly.
I read the introduction on ArcGIS automation in the documentation and learned about application's process space and "IObjectFactory".
Do I have to use that somehow to create the new Feature? How can I do that?
Or is there something else that I am doing wrong?
Any idea is apreciated!!
Thanks,
Stefan
Solved! Go to Solution.
Got it.
With a little help from stackoverflow I found a solution.
The problem was indeed that I have to use IObjectFactory to create the new geometry object.
IObjectFactory objFactory = m_application as IObjectFactory;
//Use reflection to get ClsID of PointClass.
Type pointClassType = typeof(PointClass);
string typeClsID = pointClassType.GUID.ToString("B");
IPoint esriProcessSpacePoint = (IPoint)objFactory.Create(typeClsID);
esriProcessSpacePoint.X = x;
esriProcessSpacePoint.Y = y;
newObject.Shape = (IGeometry)esriProcessSpacePoint;
Got it.
With a little help from stackoverflow I found a solution.
The problem was indeed that I have to use IObjectFactory to create the new geometry object.
IObjectFactory objFactory = m_application as IObjectFactory;
//Use reflection to get ClsID of PointClass.
Type pointClassType = typeof(PointClass);
string typeClsID = pointClassType.GUID.ToString("B");
IPoint esriProcessSpacePoint = (IPoint)objFactory.Create(typeClsID);
esriProcessSpacePoint.X = x;
esriProcessSpacePoint.Y = y;
newObject.Shape = (IGeometry)esriProcessSpacePoint;