0

How can I diagnose the above exception? In my code, I roughly do the following:

  1. Create an overlay ( overlay = new GraphicsOverlay() )
  2. Create a set of polygons ( poly = new Polygon(mappoints) where mappoints is a PointCollection)
  3. Create a graphic with the polygon geometry and a simple fill symbol for each polygon ( graphic = new Graphic() { Geometry = poly, Symbol = new SimpleFillSymbol() { Color = Colors.Red } } )
  4. Add that graphic to the overlay. ( overlay.Add(graphic) )

Then, when something changes, I will call overlay.Graphics.Clear(), then repeat steps 2-3.

When I do this, sometimes on the new Graphic(...), I will get the exception (but not every time)

I'm using Esri.ArcGISRuntime version 100.0.0.0. Any idea what's going on?

David Hope
  • 2,216
  • 16
  • 32

2 Answers2

0

Ok, it appears that the problem was that because the overlay.Graphics.Clear() was just releasing the objects to the garbage collector that the underlying native objects hadn't yet been disposed.

By forcing the garbage collector to run:

    GC.Collect();
    GC.WaitForPendingFinalizers();

This caused the objects to be disposed and elimintate the "same key" exception

David Hope
  • 2,216
  • 16
  • 32
  • received a note from the ESRI folks indicating that this is an error in their code and that my solution is the workaround for the time being. – David Hope Jan 09 '17 at 14:06
0

This is a known bug that we'll have fixed in the next update. Forcing GC will work around the issue for now.

dotMorten
  • 1,953
  • 1
  • 14
  • 10