I'm getting a new error calling GraphicsOverlay.Graphics.Add(graphic): "Cannot call this method in this context: Graphic already has an assigned id."

1945
6
11-29-2016 12:00 PM
PhilScovis
New Contributor III

This call fails intermittently, and I can't figure out why.  

Graphic is newly created in the same method; I'm definitely not adding a graphic multiple times.

Stack Trace:

at Esri.ArcGISRuntime.ArcGISException.HandleCoreError(CoreError error, Boolean throwException)
at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError(IntPtr errorHandle, Boolean throwOnFailure, GCHandle wrapperHandle)
at RuntimeCoreNet.GeneratedWrappers.CoreVector.Insert(Int64 position, CoreElement value)
at Esri.ArcGISRuntime.RuntimeCollection`1.InsertItem(Int32 index, T item)
at Esri.ArcGISRuntime.RuntimeObservableCollection`1.InsertItem(Int32 index, T item)
at Infor.Mobile.Core.WRT.Windows.UI.Mapping.EsriMap.AddMarkerInternal(IMapMarker marker)

0 Kudos
6 Replies
PreetiMaske
Esri Contributor

Can you please share your code that reproduces the problem ?

0 Kudos
PhilScovis
New Contributor III

I don't have a small sample that reproduces the error.  This code runs fine about 99% of the time, and randomly seems to fail. 

 protected override void AddMarkerInternal(IMapMarker marker)
        {
            Graphic graphic = new Graphic(EsriMapProjection.ProjectDataToMap(marker.Location));
          

            graphic.Attributes[MarkerIdAttributeName] = marker.Id;

            SetGraphicSymbolAsync(graphic, marker.ImageResourceId, true);

            try
            {
                _MarkersLayer.Graphics.Add(graphic);
            }
            catch (InvalidOperationException ex)
            {
                // Unexplained error:
                // http://arcg.is/2gGn7O5
                LogService.GetLogger().Error("Error adding marker graphic", ex);
            }

        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

As you can see, I'm creating the graphic right at the top, setting some attributes, and adding it to the layer.  SetGraphicSymbolAsync is our own method that adds a PictureMarkerSymbol to the graphic, in a platform-specific way.

Let me know if you need more information.

0 Kudos
PreetiMaske
Esri Contributor

The error you mentioned indicates you are hitting a bug but we tried reproducing the issue by writing code using similar workflow and were not able to reproduce it. There are couple things you can do to help us narrow down the problem. Can you please try changing the code with one option at a time and run your code and see if it still reproduces the problem.

- await SetGraphicSymbolAsync method that sets the picturemarkersymbol.

- Get rid of async symbol stuff altogether or replace PictureMarkerSymbol with a SimpleMarkerSymbol.

Thanks,

Preeti

0 Kudos
PhilScovis
New Contributor III

Both of these suggestions cleared up the problem entirely. 

I think for our application, it will be acceptable to await the setting of the graphic symbol, although I'd prefer to let the images load in the background.

Thanks for your attention to our little problem; let me know if there's anything more I can do to help you narrow down the cause. 

0 Kudos
PreetiMaske
Esri Contributor

Glad the workaround worked. I am still curious if I can repro the problem and find cause of failure with background loading. Will be you be able to share your code for setting platform specific image. If want you can direct email me pmaske@esri.com

-Preeti

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi Phil,

We have a candidate fix for this issue that is currently being tested. It involved some changes to our internal graphic id allocation and management. If it proves to be robust with no regressions we should be able to include it in our next release. Unfortunately we still have not been able to repro the issue with the code you provided.

Regarding your repro code, by using the await keyword you are awaiting your SetGraphicSymbolAsync task and therefore effectively doing that work in the background. The Task.Wait() call is a blocking call which would wait until the task is finished.

Cheers

Mike

0 Kudos