ArcGIS Pro SDK for .NET points to the old FeatureClass after changing Data Source of FeatureLayer

1708
11
03-11-2019 08:52 AM
AveVill
New Contributor II

Hi, Esri Technical Support

I am using ArcGIS Pro SDK for .NET version 2.2.0.12813.

Based on community sample ChangeLayerDataSource.cs I have implemented Data Source change functionality using SetDataConnection method.

featureLayer.SetDataConnection(updatedDataConnection);

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,

Ave

11 Replies
RichRuh
Esri Regular Contributor

Hi Ave,

We are investigating this situation now. I'll respond again when I have more information to share.

Thanks,

--Rich

0 Kudos
AveVill
New Contributor II

Hi Rich,

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?

Thanks!

Ave

0 Kudos
RichRuh
Esri Regular Contributor

We think this is a bug, but haven't figured out the cause or how hard it is to fix.  Is using findAndReplaceWorkspacePath an acceptable work-around?

--Rich

0 Kudos
AveVill
New Contributor II

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)

Ave

RichRuh
Esri Regular Contributor

The issue should be fixed in Pro 2.4, forthcoming this summer.

--Rich

0 Kudos
AveVill
New Contributor II

Thank you!

Ave

0 Kudos
RichRuh
Esri Regular Contributor

This is fixed in Pro 2.4.

ØysteinKristoffersen
New Contributor II

Hi Rich

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?

Thank you!

Øystein

0 Kudos
RichRuh
Esri Regular Contributor

Hi Øystein,

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?

Thanks,

--Rich

0 Kudos