I am using ArcGIS Pro SDK for .NET version 126.96.36.19913.
Based on community sample ChangeLayerDataSource.cs I have implemented Data Source change functionality using SetDataConnection method.
Everything works fine except the cases when WorkspaceFactory changes from FileGDB to SDE or the other way around, from SDE to FileGDB. After setting the new Data Connection, the new parameters are attached to the featureLayer, but when reading the layers again with MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>(), the featureLayer.GetFeatureClass() shows the old FeatureClass. After closing/saving and reopening the project the FeatureClass is updated and SDK shows it correctly with featureLayer.GetFeatureClass().
Has anyone had a similar issue and is there a way to refresh FeatureClass programmatically to be used in SDK?
Thanks in advance,
Thank you for your response and for looking into the matter!
I would just like to add that I carried out additional tests and discovered that the same problem occurs when the WorkspaceFactory does not change. However, when using the method findAndReplaceWorkspacePath, then the FeatureClass is updated.
My question is if this is the expected behaviour that FeatureClass is not updated when using SetDataConnection method or is this a bug?
I tested different cases with findAndReplaceWorkspacePath.
It works fine with the cases:
FileGDB -> FileGDB
SDE -> SDE
FileGDB -> SDE
It fails with the case:
SDE -> FileGDB
Exception thrown: 'ArcGIS.Desktop.Mapping.MappingException' in ArcGIS.Desktop.Mapping.dll ArcGISPro.exe Warning: 0 : ArcGIS.Desktop.Mapping.MappingException: Error HRESULT E_FAIL has been returned from a call to a COM component. ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component. at ArcGIS.Desktop.Internal.DesktopService._IMapAuthoringService.ReplaceLayerOrStandaloneTableWorkspace(Int32 repositoryID, String mapPath, String layerPath, String toFind, String replaceWith, Boolean validate) at ArcGIS.Desktop.Mapping.Layer.<>c__DisplayClass89_0.<FindAndReplaceWorkspacePath>b__0() at ArcGIS.Desktop.Internal.Mapping.Utilities.MakeBasicServiceCall(Action serviceCall)
I am experiencing the same problem with the SDK as Ave when it comes to FindAndReplaceWorkspacePath when changing a layers source from SDE -> FileGDB.
"Exception thrown: 'ArcGIS.Desktop.Mapping.MappingException' in ArcGIS.Desktop.Mapping.dll
ArcGISPro.exe Warning: 0 : ArcGIS.Desktop.Mapping.MappingException: Error HRESULT E_FAIL has been returned from a call to a COM component..."
I realize that this is not the main topic of this thread but since it is mentioned here and exactly what I am trying to solve I wanted to hear if you know about this issue and if it is something that will be looked into by Esri?
Ave's issue should have been fixed at Pro 2.4. What version of Pro are you using? Could you post a small code snippet about what you are trying to do?