# Clearing EditOverlay causes Key Not Present Exception

**URL:** <https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921>\
**Category:** WinForms\
**Created:** [March 6, 2012, 7:21pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921 "2012-03-06T19:21:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [March 6, 2012, 7:21pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/1 "2012-03-06T19:21:30Z")

</div>

When&nbsp;I&nbsp;clear&nbsp;all&nbsp;layers&nbsp;in&nbsp;the&nbsp;EditOverlay&nbsp;and&nbsp;add&nbsp;another&nbsp;shape&nbsp;to&nbsp;it.&nbsp;I&nbsp;get&nbsp;a&nbsp;"The&nbsp;given&nbsp;key&nbsp;was&nbsp;not&nbsp;present&nbsp;in&nbsp;the&nbsp;dictionary"&nbsp;exception.

I&nbsp;have&nbsp;attached&nbsp;a&nbsp;test&nbsp;solution&nbsp;(update&nbsp;of&nbsp;CustomTrackPolygon&nbsp;to&nbsp;show&nbsp;error).

To&nbsp;replicate:

1.&nbsp;Add&nbsp;a&nbsp;polygon&nbsp;(click,&nbsp;click,&nbsp;click,&nbsp;double&nbsp;click)

2.&nbsp;Click&nbsp;Edit&nbsp;button

3.&nbsp;Add&nbsp;another&nbsp;polygon

When&nbsp;track&nbsp;ended&nbsp;is&nbsp;fired&nbsp;for&nbsp;the&nbsp;second&nbsp;polygon&nbsp;an&nbsp;exception&nbsp;is&nbsp;thrown&nbsp;when&nbsp;I&nbsp;try&nbsp;and&nbsp;refresh&nbsp;the&nbsp;EditOverlay.

This&nbsp;is&nbsp;Desktop&nbsp;v5.0

Cheers

Steve

[CustomTrackPolygon.zip](https://community.thinkgeo.com/uploads/default/original/1X/ef3703841901773460c6625d50107f2f01541ed3.zip) (41.6 KB)

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [March 7, 2012, 10:06am UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/2 "2012-03-07T10:06:20Z")

</div>

Hello&nbsp;Steve,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;sample,&nbsp;I&nbsp;have&nbsp;recreate&nbsp;this&nbsp;problem,&nbsp;we&nbsp;are&nbsp;working&nbsp;on&nbsp;this&nbsp;find&nbsp;the&nbsp;root&nbsp;cause&nbsp;and&nbsp;fix&nbsp;it,&nbsp;please&nbsp;subscribe&nbsp;this&nbsp;post&nbsp;and&nbsp;I&nbsp;will&nbsp;let&nbsp;you&nbsp;know&nbsp;the&nbsp;result&nbsp;asap.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [March 7, 2012, 6:43pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/3 "2012-03-07T18:43:45Z")

</div>

Thanks&nbsp;Gary.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Just&nbsp;tried&nbsp;this&nbsp;with&nbsp;v5.5&nbsp;and&nbsp;get&nbsp;the&nbsp;same&nbsp;exception.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Will&nbsp;wait&nbsp;for&nbsp;your&nbsp;response.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [March 7, 2012, 6:57pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/4 "2012-03-07T18:57:07Z")

</div>

If&nbsp;I&nbsp;comment&nbsp;this&nbsp;line&nbsp;out&nbsp;  
&nbsp;&nbsp;  
&nbsp;winformsMap1.EditOverlay.ExistingControlPointsLayer.InternalFeatures.Clear();&nbsp;  
&nbsp;&nbsp;  
&nbsp;Then&nbsp;I&nbsp;no&nbsp;longer&nbsp;get&nbsp;an&nbsp;exception&nbsp;(&nbsp;I&nbsp;do&nbsp;however&nbsp;get&nbsp;the&nbsp;control&nbsp;points&nbsp;left&nbsp;on&nbsp;the&nbsp;screen).&nbsp;Might&nbsp;point&nbsp;at&nbsp;the&nbsp;problem?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [March 7, 2012, 7:49pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/5 "2012-03-07T19:49:37Z")

</div>

Just&nbsp;tried&nbsp;with&nbsp;latest&nbsp;daily&nbsp;build&nbsp;(5.5.108)&nbsp;and&nbsp;get&nbsp;the&nbsp;same&nbsp;exception.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [March 8, 2012, 11:17am UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/6 "2012-03-08T11:17:12Z")

</div>

Hello&nbsp;Steve,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;will&nbsp;post&nbsp;result&nbsp;here&nbsp;as&nbsp;soon&nbsp;as&nbsp;we&nbsp;resloved&nbsp;this.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [March 13, 2012, 9:21pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/7 "2012-03-13T21:21:15Z")

</div>

Hi&nbsp;Gary&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;update&nbsp;on&nbsp;this?&nbsp;I&nbsp;have&nbsp;a&nbsp;customer&nbsp;waiting&nbsp;for&nbsp;a&nbsp;bug&nbsp;fix&nbsp;from&nbsp;us&nbsp;and&nbsp;I&nbsp;need&nbsp;to&nbsp;give&nbsp;them&nbsp;an&nbsp;ETA.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Cheers&nbsp;  
&nbsp;&nbsp;  
&nbsp;Steve&nbsp;

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [March 14, 2012, 2:11pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/8 "2012-03-14T14:11:21Z")

</div>

Hello&nbsp;Steve,

Sorry&nbsp;for&nbsp;waiting,&nbsp;this&nbsp;problem&nbsp;connect&nbsp;to&nbsp;some&nbsp;other&nbsp;question,&nbsp;so&nbsp;it&nbsp;cost&nbsp;a&nbsp;lot&nbsp;time.

when&nbsp;I&nbsp;invoked&nbsp;CalculateAllControlPoints&nbsp;function,&nbsp;I&nbsp;found&nbsp;that&nbsp;the&nbsp;internal&nbsp;features’&nbsp;RTree&nbsp;had&nbsp;been&nbsp;rebuilt.&nbsp;However,&nbsp;after&nbsp;I&nbsp;did&nbsp;some&nbsp;operation&nbsp;to&nbsp;these&nbsp;features&nbsp;I&nbsp;didn’t&nbsp;recall&nbsp;“BuildIndex”&nbsp;method.&nbsp;And&nbsp;these&nbsp;new&nbsp;features&nbsp;are&nbsp;not&nbsp;included&nbsp;in&nbsp;RTree&nbsp;dictionary.&nbsp;It&nbsp;will&nbsp;throw&nbsp;the&nbsp;exception&nbsp;when&nbsp;I&nbsp;got&nbsp;features&nbsp;by&nbsp;RTree&nbsp;index.

We&nbsp;have&nbsp;two&nbsp;solution&nbsp;for&nbsp;this&nbsp;issue:  
  
1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;CalculateAllControlPoints&nbsp;should&nbsp;be&nbsp;invoked&nbsp;after&nbsp;the&nbsp;internal&nbsp;features&nbsp;have&nbsp;been&nbsp;changed,&nbsp;because&nbsp;the&nbsp;BuildIndex&nbsp;would&nbsp;be&nbsp;invoked,&nbsp;the&nbsp;RTree&nbsp;index&nbsp;would&nbsp;be&nbsp;reconstructed.&nbsp;The&nbsp;codes&nbsp;snipped&nbsp;as&nbsp;follows:  
  
  
  
`winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Clear();             // need this to clear edit drag/resize controls            winformsMap1.EditOverlay.ExistingControlPointsLayer.InternalFeatures.Clear();            winformsMap1.EditOverlay.ResizeControlPointsLayer.InternalFeatures.Clear();            winformsMap1.EditOverlay.RotateControlPointsLayer.InternalFeatures.Clear();            winformsMap1.EditOverlay.DragControlPointsLayer.InternalFeatures.Clear();             winformsMap1.EditOverlay.CalculateAllControlPoints();             winformsMap1.Refresh(new Overlay[] { winformsMap1.EditOverlay });`2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;we&nbsp;can&nbsp;solve&nbsp;the&nbsp;issue&nbsp;with&nbsp;BeginTransaction&nbsp;and&nbsp;CommitTransaction.&nbsp;The&nbsp;codes&nbsp;snipped&nbsp;as&nbsp;follows:  
  
`winformsMap1.EditOverlay.DragControlPointsLayer.Open();            winformsMap1.EditOverlay.DragControlPointsLayer.FeatureSource.BeginTransaction();            winformsMap1.EditOverlay.DragControlPointsLayer.InternalFeatures.Clear();            winformsMap1.EditOverlay.DragControlPointsLayer.FeatureSource.CommitTransaction();            winformsMap1.EditOverlay.DragControlPointsLayer.Close();`

Please&nbsp;let&nbsp;us&nbsp;know&nbsp;if&nbsp;you&nbsp;still&nbsp;can't&nbsp;let&nbsp;it&nbsp;work.

Regards,

Gary

---

<div class="post-metadata">

**Author:** ![Steve1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@Steve1](https://community.thinkgeo.com/u/Steve1)\
**Post date:** [March 14, 2012, 2:50pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/9 "2012-03-14T14:50:26Z")

</div>

Thanks&nbsp;Gary

After&nbsp;you&nbsp;pointed&nbsp;me&nbsp;in&nbsp;the&nbsp;correct&nbsp;direction&nbsp;I&nbsp;have&nbsp;managed&nbsp;to&nbsp;make&nbsp;an&nbsp;even&nbsp;easier&nbsp;method&nbsp;that&nbsp;works:

&nbsp;

`    private void ClearEditOverlay()    {        gisMap.EditOverlay.EditShapesLayer.InternalFeatures.Clear();        gisMap.EditOverlay.CalculateAllControlPoints();         gisMap.Refresh(new Overlay[] { gisMap.EditOverlay });    }`  
  
Cheers  
  
Steve

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [March 15, 2012, 2:19pm UTC](https://community.thinkgeo.com/t/clearing-editoverlay-causes-key-not-present-exception/1921/10 "2012-03-15T14:19:09Z")

</div>

Hello&nbsp;Steve,&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;are&nbsp;welcome&nbsp;and&nbsp;thanks&nbsp;for&nbsp;sharing&nbsp;your&nbsp;experience.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary
