When reordering layers, even those that are not the ones loading, it is possible to hit this exception. Note that the spatial reference was already set on the map view. Sample callstack:
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.Insert(Int32 index, T item)
at Esri.ArcGISRuntime.Controls.CoreLayerCollection.MoveLayer(Layer layer)
at Esri.ArcGISRuntime.Controls.ViewBase.HandleLayersMoved(CoreLayerCollection layerManager, IEnumerable`1 movedLayers)
at Esri.ArcGISRuntime.Controls.ViewBase.<OnLayersChanged>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Esri.ArcGISRuntime.Controls.ViewBase.<OnLayerCollectionChanged>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
awaiting LayersLoadedAsync before doing any layer moves appears to avoid the issue, but I am not 100% sure
I have not seen the issue when adding or removing layers. It only has manifested itself when moving layers.
Hi,
We are also seeing this issue occur frequently since moving to the latest version of the runtime (10.2.7). With previous versions this was not an issue. Our code hasn't changed, but we now get an awful lot of these which cause our application to crash.
Is a fix for this being investigated? Argument out of range exception should not be difficult to put some preventative code around at the very least.
Hi Jon,
When you say you have moved to the latest version, do you mean v10.2.7 or v100?
Cheers
Mike
Hi Mike,
We are running 10.2.7 as stated above.
"since moving to the latest version of the runtime (10.2.7)."
We have been using the runtime since it was in beta and been through each version without having this issue. So it certainly appears to have been introduced in 10.2.7.
Regards,
Jon
Hi,
Do you have a code sample that reproduces this issue? I do see some changes in that area for the v10.2.7 release and would like to confirm it's no longer an issue in the recently released v100.
Cheers
Mike
Hi Mike,
It's awkward to provide a sample which reproduces this due to the size and nature of the application in which we are experiencing the exception.
Is this an issue which you will be looking in to further as part of your support for 10.2.7? We are understandably reluctant to move our code over to v100 at this point in time.
Regards,
Jon
Hi Jon,
Can you provide a snippet of code that shows where (in the MapView/Map/Layer lifecycle) and how you are moving layers in the collection?
Cheers
Mike
Hi Mike,
We are moving layers as below, with the indexes appearing valid at runtime.
For Each Layer As Layer In newOrder
Dim newIndex As Integer = newOrder.IndexOf(Layer)
Dim existingIndex As Integer = SpatialMap.Layers.IndexOf(Layer)
If newIndex <> existingIndex Then
SpatialMap.Layers.Move(existingIndex, newIndex)
End If
Next
Regards,
Jon
Hi Mike,
Any news on this? Was the example provided sufficient? Or do you need further information?