ThinkGeo.com    |     Documentation    |     Premium Support

The given key was not present in the dictionary

 


We are hitting this exception using the new release, and not sure of the cause.  Can you suggest what might cause this, or if there is anyway to find the key involved?


The given key was not present in the dictionary.


   at System.ThrowHelper.ThrowKeyNotFoundException()

   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

   at ThinkGeo.MapSuite.Core.GeoCollection`1.get_Item(String key)

   at ThinkGeo.MapSuite.Core.InMemoryFeatureSource.GetFeaturesBasedOnCachedBoundingBoxes(RectangleShape extent, IEnumerable`1 returningColumnNames)

   at ThinkGeo.MapSuite.Core.InMemoryFeatureSource.GetFeaturesInsideBoundingBoxCore(RectangleShape boundingBox, IEnumerable`1 returningColumnNames)

   at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesForDrawingCore(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)

   at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesForDrawing(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames)

   at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers)

   at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers)

   at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas)

   at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.x5021a7a45adbb9ee(Object x3faa3e674cef60b0)

   at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)

   at System.Threading.ExecutionContext.runTryCode(Object userData)

   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)

   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)


 




 It it helps, we tracked this down to a side effect of the following code. Here the user has finished editing onscreen shapes and we want to clear them from the layer. 
  
         ///  
         /// Clears the current user region shape 
         ///  
         internal void ClearSelection() 
         { 
             SelectedShapeOverlay.Lock.EnterWriteLock(); 
             ThinkGeoMap.EditOverlay.Lock.EnterWriteLock(); 
             try 
             { 
                 //SelectedShapeLayer.InternalFeatures.Clear(); 
                 ThinkGeoMap.EditOverlay.EditLayer.InternalFeatures.Clear(); 
                 ThinkGeoMap.EditOverlay.CalculateAllControlPoints(); 
             } 
             finally 
             { 
                 ThinkGeoMap.EditOverlay.Lock.ExitWriteLock(); 
                 SelectedShapeOverlay.Lock.ExitWriteLock(); 
             } 
         } 
  
 If the commented line is allowed to run then the exception occurs soon after.

Gordon, 
  
 We couldn’t recreate this problem. Can you send us a small demo to recreate it? Also please let us know the version you are using which can easily got by the static method WinformMap.GetVersion(). 
  
 Thanks, 
  
 Ben 
  
   
  



 Not sure how to put together a small demo as we don’t know what is causing it, other than that line above.  
  
 To help narrow it down, could you tell me what dictionary is being accessed in the GetFeaturesBasedOnCachedBoundingBoxes function (see stack trace)? 



 Sorry, forgot to post the version. These exceptions are occuring on the latest RC, 3.0.415.0… and seem not to be present on the previous RC 3.0.362. 
  
 Environment is Windows XP SP3, Single core Athlon CPU. 
  
 System.Collections.Generic.KeyNotFoundException was unhandled 
   Message=“The given key was not present in the dictionary.” 
   Source=“mscorlib” 
   StackTrace: 
        at System.ThrowHelper.ThrowKeyNotFoundException() 
        at System.Collections.Generic.Dictionary`2.get_Item(TKey key) 
        at ThinkGeo.MapSuite.Core.GeoCollection`1.get_Item(String key) 
        at ThinkGeo.MapSuite.Core.InMemoryFeatureSource.GetFeaturesBasedOnCachedBoundingBoxes(RectangleShape extent, IEnumerable`1 returningColumnNames) 
        at ThinkGeo.MapSuite.Core.InMemoryFeatureSource.GetFeaturesInsideBoundingBoxCore(RectangleShape boundingBox, IEnumerable`1 returningColumnNames) 
        at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesForDrawingCore(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames) 
        at ThinkGeo.MapSuite.Core.FeatureSource.GetFeaturesForDrawing(RectangleShape boundingBox, Double screenWidth, Double screenHeight, IEnumerable`1 returningColumnNames) 
        at ThinkGeo.MapSuite.Core.FeatureLayer.DrawCore(GeoCanvas canvas, Collection`1 labelsInAllLayers) 
        at ThinkGeo.MapSuite.Core.Layer.Draw(GeoCanvas canvas, Collection`1 labelsInAllLayers) 
        at ThinkGeo.MapSuite.DesktopEdition.LayerOverlay.DrawCore(GeoCanvas canvas) 
        at ThinkGeo.MapSuite.DesktopEdition.Overlay.Draw(GeoCanvas canvas) 
        at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xef6cc4fa8fda72d7(RectangleShape xb35a33b423b17f65, Overlay x99251f66cdabc2ad, Int32 xa209325f5c895f7e, Int32 x7454a0d1965919b1, GeographyUnit xbb704b4400ce6f76) 
        at ThinkGeo.MapSuite.DesktopEdition.WinformsMap.xef6cc4fa8fda72d7(Object x9c95f4613bdc3113) 
        at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state) 
        at System.Threading.ExecutionContext.runTryCode(Object userData) 
        at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
        at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
        at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
        at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack) 
        at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state) 
   InnerException:  
  
  
  
 Is there anything you can help me with the obfuscation, to maybe see which of our layers of overlays is involved in this … I’m not sure how to proceed in tracing this as it does not seem to be directly associated with a particular call we make.

Hi Gordon,


This exception is raised in some InMemoryFeatureLayer of some LayerOverlay (including the EditInteractiveOverlay.EditLayer) in your application based on the stack trace. You should check each InMemoryFeatureLayer to see if the following block of code or some code like this exists in your application.


inMemoryFeatureLayer.EditTools.BeginTransaction();
inMemoryFeatureLayer.EditTools.Add(new Feature());
inMemoryFeatureLayer.EditTools.CommitTransaction();


 
If so, when you modify the feature in this InMemoryFeatureLayer like this:


inMemoryFeatureLayer.InternalFeatures.Add(new Feature());
inMemoryFeatureLayer.InternalFeatures.Clear();



 
You should call the function inMemoryFeatureLayer.BuildIndex() after modifying the internal features.
Hope this can help and any more questions please let us know.
Thanks,
sun