ThinkGeo.com    |     Documentation    |     Premium Support

ThinkGeo 14.3.0 Map Initialization Exception

I just moved to the 14.3.0 build and am getting an exception that I am having a hard time figuring out what is causing it:

Message “Object reference not set to an instance of an object.” string
Source “ThinkGeo.UI.Wpf” string

	StackTrace	"   at ThinkGeo.UI.Wpf.Overlay.O0Q=(Exception e, String memberName)\r\n   at ThinkGeo.UI.Wpf.Overlay.Transform(RectangleShape targetExtent)\r\n   at ThinkGeo.UI.Wpf.MapViewBase.lUM=(IEnumerable`1 overlays, RectangleShape targetExtent)\r\n   at ThinkGeo.UI.Wpf.MapViewBase.kEM=(Object sender, SizeChangedEventArgs e)\r\n   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)\r\n   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)\r\n   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)\r\n   at System.Windows.FrameworkElement.OnRenderSizeChanged(SizeChangedInfo sizeInfo)\r\n   at System.Windows.ContextLayoutManager.fireSizeChangedEvents()\r\n   at System.Windows.ContextLayoutManager.UpdateLayout()\r\n   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)\r\n   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()\r\n   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)\r\n   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)\r\n   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)\r\n   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)"	string
  •   TargetSite	{Void O0Q=(System.Exception, System.String)}	System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
    

I am loading a project from serialization. We have templated visualizations that are laid out in a grid based on what the user has loaded. Because of the complexity of the map, I am not able to accomplish it all by data binding and there are some operations on the MapView and overlays. I did not see this exception in previous versions (not sure which 14.2 version I was using before this).

It looks a little like:


but there is a MapView already inside a grid. The MapLoaded event handler has already processed. The exception doesn’t seem to be in my initialization code but afterwards.
Any help would be appreciated.

Hi Robert,

I found the exception is thrown because the MapView is resized before initialized. In v14.3, the mapView.CurrentExtent returns null before the map is initialized (when its width/height equals to 0), which causes this exception.

We just added a null check in the latest beta package (v14.4.0-beta012), please pull the latest and you should not see this exception.

If you don’t want to upgrade, you can also do the following to eat the exception

   overlay.ThrowingException += overlay_ThrowingException;
   private void overlay_ThrowingException(object sender, ThrowingExceptionOverlayEventArgs e)
    {
        e.Handled = true; // eat the exception
    }

or the following to suppress the exception

   overlay.ThrowingExceptionMode = ThrowingExceptionMode.SuppressException;

Let me know if you have any more questions after work it through.

Thanks,
Ben

Ok, I’ve spent too much time on this for now.

I updated to 14.4.0-b012 and it did not fix the issue.
I also added the exception handlers to every overlay that I’m creating and it didn’t help (I also added handlers to deprecated drawingexceptions).

I also removed calls to everything I was adding to the map and it still generated the exception with a completely empty map.

I was able to get around exceptions by changing the XAML code:

<wpf:MapView Grid.Column=“0” x:Name=“mapView” Loaded=“mapView_Loaded”
MapClick=“mapView_OnMapClick” MapResizeMode=“PreserveScaleAndCenter”>
<b:Interaction.Triggers>
<b:EventTrigger EventName=“SizeChanged”>
<b:InvokeCommandAction Command="{Binding MapSizeChangedCommand}"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</wpf:MapView>

Removing the MapResizeMode yields no exceptions. Hopefully this helps you track down what is happening (the interaction trigger is ok). We do need the MapResizeMode though as the control is often resized when other controls are added to the grid.

All right, I think I’ve figured it out. We just built a new beta (013) — please pull it and give it a try.

I was able to reproduce the exception when resizing the map in PreserveScaleAndCenter or PreserveExtent mode before the map is refreshed. The issue occurs because overlays are only initialized when the map is drawn (e.g., via map.RefreshAsync() ), if the map is resized before any refresh, it triggers a call to Overlay.Transform(RectangleShape targetExtent) , but the overlay hasn’t been initialized yet, which causes the exception.

FYI: we have 2 users asking the similar questions here: Centerpoint+Currentscale problem - ThinkGeo UI for Desktop / WPF - ThinkGeo Discussion Forums

Thanks,
Ben