AnsweredAssumed Answered

Issue Basemap & IEnumLayer

Question asked by afmaps on Dec 5, 2013
Latest reply on Dec 5, 2013 by afmaps
Afternoon everyone -
The following works great...

  Dim uid As ESRI.ArcGIS.esriSystem.IUID = New ESRI.ArcGIS.esriSystem.UIDClass   uid.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}" 'IDataLayer    Try     Dim enumLayer As ESRI.ArcGIS.Carto.IEnumLayer = map.Layers((CType(uid, ESRI.ArcGIS.esriSystem.UID)), True) ' Explicit Cast     enumLayer.Reset()     Dim layer As ESRI.ArcGIS.Carto.ILayer = enumLayer.Next     Do While Not (layer Is Nothing)         layer = enumLayer.Next()     Loop   Catch ex As System.Exception     'System.Windows.Forms.MessageBox.Show("No layers of type: " + uid.Value.ToString);   End Try 


Until you add a basemap (e.g. light grey canvas map)
Even though its "Reference" layer is not a data layer IEnumLayer is continually picking up the layer - so when you do layer = enumLayer.Next() you get this wonderful error:

System.InvalidCastException was caught
  Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.ILayer2'.
This operation failed because the QueryInterface call on the COM component for the interface with
IID '{599DEE2E-2182-4E54-8A86-725145C9D989}' failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).


Has anyone else had similar difficulties?

Thank You
Alex

Outcomes