Null spatial reference inside location manager

1246
8
10-05-2020 08:53 AM
JeremyBridges
Occasional Contributor

FYI: we received the following stack trace from our telemetry recently. This was using the .NET Runtime running on iOS, using Xamarin. Hopefully, it helps to fix some bugs that haven't been discovered yet.

System.ArgumentException: Invalid argument: The position's spatial reference is null

Stack trace:

  • at Esri.ArcGISRuntime.ArcGISException.HandleCoreError (RuntimeCoreNet.GeneratedWrappers.CoreError error, System.Boolean throwException)
  • at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError (System.IntPtr errorHandle, System.Boolean throwOnFailure, System.Runtime.InteropServices.GCHandle wrapperHandle)
  • at RuntimeCoreNet.GeneratedWrappers.CoreLocation..ctor (RuntimeCoreNet.GeneratedWrappers.CoreDateTime timestamp, RuntimeCoreNet.GeneratedWrappers.CorePoint pointHandle, System.Double horizontalAccuracy, System.Double verticalAccuracy, System.Double velocity, System.Double course, System.Boolean lastKnown)
  • at Esri.ArcGISRuntime.Location.Location..ctor (System.Nullable timestamp, Esri.ArcGISRuntime.Geometry.MapPoint position, System.Double horizontalAccuracy, System.Double verticalAccuracy, System.Double velocity, System.Double course, System.Boolean isLastKnown)
  • at Esri.ArcGISRuntime.Location.SystemLocationDataSource.RaiseLocationChanged (Esri.ArcGISRuntime.Internal.Geoposition geoposition, System.Boolean isLastKnown)
  • at Esri.ArcGISRuntime.Location.SystemLocationDataSource.Locator_PositionChanged (System.Object sender, Esri.ArcGISRuntime.Internal.PositionChangedEventArgs args)
  • at Esri.ArcGISRuntime.Internal.Geolocator.OnPositionChanged ()
  • at Esri.ArcGISRuntime.Internal.Geolocator.UpdateCurrentPosition (CoreLocation.CLLocation location)
  • at Esri.ArcGISRuntime.Internal.Geolocator.LocationManager_LocationsUpdated (System.Object sender, CoreLocation.CLLocationsUpdatedEventArgs e)
  • at CoreLocation.CLLocationManager+_CLLocationManagerDelegate.LocationsUpdated (CoreLocation.CLLocationManager manager, CoreLocation.CLLocation[] locations)
  • at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  • at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
  • at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
0 Kudos
8 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi Jeremy,

Thanks for sharing the call stack. What version are you using?

Thanks

Mike

0 Kudos
JeremyBridges
Occasional Contributor

Runtime for Xamarin, 100.8

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

If you have time, it would be great to know if you see the same error with 100.9 (we did some work in that area in the 100.9 release).

Thanks

Mike

0 Kudos
ahassan3
New Contributor

This issue has recently been happening on our WPF application in version 100.12. Here is the full stack of the error: 

Null pointer: map_point.get_spatial_reference()
at Esri.ArcGISRuntime.ArcGISException.HandleCoreError(CoreError error, Boolean throwException)
at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError(IntPtr errorHandle, Boolean throwOnFailure, GCHandle wrapperHandle)
at RuntimeCoreNet.GeneratedWrappers.CoreMapView.LocationToScreen(CorePoint mapPoint)
at Esri.ArcGISRuntime.UI.Controls.MapView.LocationToScreen(MapPoint location)
at Esri.ArcGISRuntime.UI.Controls.GeoView.<>c__DisplayClass238_0.<ArrangeViewOverlays>b__1(MapPoint p, LocationVisibility& visibility)
at Esri.ArcGISRuntime.UI.Controls.MapOverlayPanel.ArrangeMapOverlayItem(OverlayItem child)
at Esri.ArcGISRuntime.UI.Controls.MapOverlayPanel.ArrangeOverride(Size finalSize)
at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
at System.Windows.UIElement.Arrange(Rect finalRect)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
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)

0 Kudos
ahassan3
New Contributor

@MichaelBranscomb any help on this issue would be great. I downgraded to 100.10 and it's working fine. However, we needed to update 100.12 to fix another issue

 

0 Kudos
MatveiStefarov
Esri Contributor

Hello @ahassan3!  The stack trace that you shared points to MapView Overlays  -- is your application using this feature?

I was able to reproduce this exception by creating a MapView overlay with a ViewOverlayAnchor point that has no SpatialReference.  I don't think that should throw -- I am investigating whether this is a bug in Runtime -- but a workaround should be simple.  Ensure that your application always sets the SpatialRefrence on the ViewOverlayAnchors.

Please let me know if this helps!

0 Kudos
ahassan3
New Contributor

@MatveiStefarov  Upon investigating my issue, i am seeing that the mapview has a null spatial reference. What's making it null ? before setting the graphicsoverlay, i am setting the

MapView.map = new Map (SpatialReferences.WebMercator)

Shouldn't this set the mapview's reference. I can subscribe to the spatialreference changed event and check when that becomes null. How can i set the spatialreference once it becomes null. 

0 Kudos
MatveiStefarov
Esri Contributor

Setting MapView.Map is the right way to set SpatialReference.  In your example, I would expected MapView.SpatialReference property to be set to WebMercator right away.

MapView's SpatialReference can only be null if its Map property is null, or if it's set to a non-loaded/failed-to-load Map object.

Looking through MapOverlayPanel source on our end, I see that a null SpatialReference on the GeoView can indeed cause an exception similar to your stack trace, but only if ViewOverlayAnchor attached property is not set (or set too late).  This also seems like a Runtime bug to me, and I'll investigate it.

The workaround for this one would be to ensure that ViewOverlayAnchor property is set before an overlay is added to MapView.

If this still does not solve the problem, could you please share how you use Runtime in more detail?

0 Kudos