I'm trying to prevent Pro from importing MXD as new map. I want to insert content of the document as a group layer within current map.
What I tried:
<SPAN class="keyword token">var</SPAN> item <SPAN class="operator token">=</SPAN> ItemFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Create</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"doc.mxd"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> currentMap <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> map <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> MapFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateMapFromItem</SPAN><SPAN class="punctuation token">(</SPAN>item<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">await</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> groupLayer <SPAN class="operator token">=</SPAN> LayerFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateGroupLayer</SPAN><SPAN class="punctuation token">(</SPAN>currentMap<SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> map<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> layer <SPAN class="keyword token">in</SPAN> map<SPAN class="punctuation token">.</SPAN>Layers<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
groupLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveLayer</SPAN><SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="punctuation token">.</SPAN>MaxValue<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I get exception on line 11:
ArcGIS.Desktop.Mapping.MappingException
HResult=0x80004005
Message=Source layer's container not found.
Source=ArcGIS.Desktop.Mapping
Inner Exception 1:
COMException: Source layer's container not found.
Is it possible to import map as group layer in some way?