System.ArgumentException when using ShowCalloutForGeoElement

1469
5
10-25-2017 07:26 AM
ChrisSmith10
New Contributor II

I'm getting the exception below when calling ShowCalloutForGeoElement. I assume I'm doing something incorrectly but I'm unable to figure out what. If I click on the dashed line in the screenshot I receive the exception at the bottom. However, if I click on the triangle I do not get the exception. I'm using v100.1 with WPF. Any guidance would be appreciated. Thank you.

Code Sample:

private async void MyMapViewOnGeoViewTapped(object o, GeoViewInputEventArgs geoViewInputEventArgs)
{
  MyMapView.DismissCallout();
  foreach (var graphicsOverlay in MyMapView.GraphicsOverlays)
  {
    var result = await MyMapView.IdentifyGraphicsOverlayAsync(graphicsOverlay, geoViewInputEventArgs.Position, 10, false, 1);
    if (result.Graphics.Count >= 1)
    {
       // Create a new callout definition using the formatted string
       var myCalloutDefinition = new CalloutDefinition("Title", "Detailed text");
 
       // Display the callout
       MyMapView.ShowCalloutForGeoElement(result.Graphics[0], geoViewInputEventArgs.Position, myCalloutDefinition);
       geoViewInputEventArgs.Handled = true;
       break;
    }
  }
}

Screenshot:

Exception:

Exception: [10/25/2017 2:22:23 PM]     [High]     System.ArgumentException: Value does not fall within the expected range.
   at Esri.ArcGISRuntime.Geometry.GeometryUtils.ValidateSpatialReference(SpatialReference inSR1, SpatialReference inSR2, Boolean ignoreNulls)
   at Esri.ArcGISRuntime.Geometry.GeometryEngine.NearestCoordinate(Geometry geometry, MapPoint point)
   at Esri.ArcGISRuntime.UI.Controls.GeoView.<ShowCalloutForGeoElement>d__65.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   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()
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   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.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at EdgeTech.OperatorConsole.App.Main()
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
Value does not fall within the expected range.
Tags (1)
0 Kudos
5 Replies
dotMorten_esri
Esri Frequent Contributor

It looks like it's trying to project your graphic geometry and fails. Does your geometry not have a spatial reference? (ie. result.Graphics[0].Geometry.SpatialReference == null)

0 Kudos
dotMorten_esri
Esri Frequent Contributor

...or does it differ from the spatial reference of the mapview?

0 Kudos
ChrisSmith10
New Contributor II

Graphic 1 (dashed line, failure case)

Graphic Spatial ref = SpatialReference[Wkid=4326], Map spatial ref = SpatialReference[Wkid=102100]

The Graphic Geometry is a Polyline with 1 parts, and 20+ points

Graphic 2 (triangle, working case)

Graphic Spatial ref = SpatialReference[Wkid=4326], Map spatial ref = SpatialReference[Wkid=102100]

The Graphic Geometry is a MapPoint

0 Kudos
dotMorten_esri
Esri Frequent Contributor

I think you might be hitting a bug here. Does the problem go away if the graphics has the same spatial reference as the mapview?
graphic.Geometry = GeometryEngine.Project(graphic.Geometry, mapView.SpatialReference);

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi,

This should be resolved in the recent v100.2 release.

Please download the latest Visual Studio extension from ArcGIS for Developers or update your NuGet packages via the NuGet package manager.

Cheers

Mike

0 Kudos