<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Issue Basemap &amp;amp;amp;amp;amp; IEnumLayer in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340548#M8940</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Afternoon everyone - &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The following works great...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; Dim uid As ESRI.ArcGIS.esriSystem.IUID = New ESRI.ArcGIS.esriSystem.UIDClass &amp;nbsp; uid.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}" 'IDataLayer&amp;nbsp; &amp;nbsp; Try &amp;nbsp;&amp;nbsp;&amp;nbsp; Dim enumLayer As ESRI.ArcGIS.Carto.IEnumLayer = map.Layers((CType(uid, ESRI.ArcGIS.esriSystem.UID)), True) ' Explicit Cast &amp;nbsp;&amp;nbsp;&amp;nbsp; enumLayer.Reset() &amp;nbsp;&amp;nbsp;&amp;nbsp; Dim layer As ESRI.ArcGIS.Carto.ILayer = enumLayer.Next &amp;nbsp;&amp;nbsp;&amp;nbsp; Do While Not (layer Is Nothing) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = enumLayer.Next() &amp;nbsp;&amp;nbsp;&amp;nbsp; Loop &amp;nbsp; Catch ex As System.Exception &amp;nbsp;&amp;nbsp;&amp;nbsp; 'System.Windows.Forms.MessageBox.Show("No layers of type: " + uid.Value.ToString); &amp;nbsp; End Try &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Until you add a basemap (e.g. light grey canvas map)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;System.InvalidCastException was caught&lt;BR /&gt;&amp;nbsp; Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.ILayer2'. &lt;BR /&gt;This operation failed because the QueryInterface call on the COM component for the interface with &lt;BR /&gt;IID '{599DEE2E-2182-4E54-8A86-725145C9D989}' failed due to the following error: No such interface supported &lt;BR /&gt;(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone else had similar difficulties? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank You&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Alex&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Dec 2013 12:59:40 GMT</pubDate>
    <dc:creator>AlexandraFairbarns</dc:creator>
    <dc:date>2013-12-05T12:59:40Z</dc:date>
    <item>
      <title>Issue Basemap &amp;amp;amp;amp; IEnumLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340548#M8940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Afternoon everyone - &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The following works great...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp; Dim uid As ESRI.ArcGIS.esriSystem.IUID = New ESRI.ArcGIS.esriSystem.UIDClass &amp;nbsp; uid.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}" 'IDataLayer&amp;nbsp; &amp;nbsp; Try &amp;nbsp;&amp;nbsp;&amp;nbsp; Dim enumLayer As ESRI.ArcGIS.Carto.IEnumLayer = map.Layers((CType(uid, ESRI.ArcGIS.esriSystem.UID)), True) ' Explicit Cast &amp;nbsp;&amp;nbsp;&amp;nbsp; enumLayer.Reset() &amp;nbsp;&amp;nbsp;&amp;nbsp; Dim layer As ESRI.ArcGIS.Carto.ILayer = enumLayer.Next &amp;nbsp;&amp;nbsp;&amp;nbsp; Do While Not (layer Is Nothing) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer = enumLayer.Next() &amp;nbsp;&amp;nbsp;&amp;nbsp; Loop &amp;nbsp; Catch ex As System.Exception &amp;nbsp;&amp;nbsp;&amp;nbsp; 'System.Windows.Forms.MessageBox.Show("No layers of type: " + uid.Value.ToString); &amp;nbsp; End Try &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Until you add a basemap (e.g. light grey canvas map)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;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:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;System.InvalidCastException was caught&lt;BR /&gt;&amp;nbsp; Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Carto.ILayer2'. &lt;BR /&gt;This operation failed because the QueryInterface call on the COM component for the interface with &lt;BR /&gt;IID '{599DEE2E-2182-4E54-8A86-725145C9D989}' failed due to the following error: No such interface supported &lt;BR /&gt;(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone else had similar difficulties? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank You&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Alex&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 12:59:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340548#M8940</guid>
      <dc:creator>AlexandraFairbarns</dc:creator>
      <dc:date>2013-12-05T12:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Basemap &amp; IEnumLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340549#M8941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you certain that the error is occurring on that line of code?&amp;nbsp; The error says it is unable to cast the object to ILayer2.&amp;nbsp; Nowhere in the code you posted are you attempting a cast to ILayer2 (only ILayer) so I don't see any way for that exception to be thrown.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 13:27:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340549#M8941</guid>
      <dc:creator>NeilClemmons</dc:creator>
      <dc:date>2013-12-05T13:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Issue Basemap &amp; IEnumLayer</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340550#M8942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Are you certain that the error is occurring on that line of code?&amp;nbsp; The error says it is unable to cast the object to ILayer2.&amp;nbsp; Nowhere in the code you posted are you attempting a cast to ILayer2 (only ILayer) so I don't see any way for that exception to be thrown.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;Thanks Neil you inadvertently solved the issue. The code posted was from ArcGIS Online as I didn't have the code directly in front of me. The only difference in my code is that I implement ILayer2 since ESRI advises:&lt;/SPAN&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; Provides access to members that work with all layers. Note: the ILayer interface has been superseded byILayer2. Please consider using the more recent version.&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt; I changed code back to using ILayer - it works perfectly. Obviously ILayer2 has not been implemented for this particular layer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 14:05:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/issue-basemap-amp-amp-amp-amp-ienumlayer/m-p/340550#M8942</guid>
      <dc:creator>AlexandraFairbarns</dc:creator>
      <dc:date>2013-12-05T14:05:18Z</dc:date>
    </item>
  </channel>
</rss>

