I am using Telerik.Windows.Controls for Wpf version 2021.1.233, and have reports from a customer that our application is crashing with the following error included below. As you can see the call stack is not terribly helpful, so I am hoping that either someone else has run into this, or someone from Telerik can offer some insight as to what might be null in the MapSourceInitializeCompleted handler so I can look into preventing this error.
Briefly, my application opens a window with a RadMap, draws a pushpin or two on the map, and the user can close the window at any point. After a period of time the window can also be closed by the application without any user interaction if certain criteria are met. I am fairly sure that the window with the map opens and displays correctly. I think the crash may be related to either an update to the map (drawing the pushpin), or closing the window containing the map, but that is a best guess at this point.
.NET Core Version: 3.1.27Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Controls.Map.TilePresenter.MapSourceInitializeCompleted(Object sender, EventArgs e)
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)
--- End of stack trace from previous location where exception was thrown ---
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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
I will work on isolating the map control setup and closing for your review. Finding the time to do it has been a major obstacle the last month, so it may take a while longer.
Hello Header Kyle,
Please take as much time as needed to review this behavior. Once you are ready, I will be happy to debug the project on my end and provide further information based on it.
I have reproduced the map control setup and usage in a simple solution available here: https://www.dropbox.com/s/z0fijtwqqa4w87n/SampleTelerikMappingApp.zip
If there is any additional information I can provide, please let me know. I appreciate any insight you may have.
Martin,
Unfortunately there are no known steps to reliably reproduce the crash. It happens for customers of our product, but I have never been able to reproduce even it with the exact same code they are running. Sometimes it will happen more than once in half an hour, sometimes it will be 3 or 4 hours between crashes. The one thing that is consistent is the entry in Windows Log Viewer is always what I posted above.
I updated the sample app linked above slightly to include an update to the map location while the map window is open. This is something that theoretically can happen in the full application that is experiencing the crash, but as you will see even that does not guarantee the crash will occur.
My apologies that I cannot provide an example that reliably reproduces the issue; I know that would make things substantially easier for all of us.
I am afraid that without reproducing this I cannot suggest a proper solution or a fix candidate. A blind fix can be provided, but this code is accessed from another thread in some occasions and my experience shows that making blind fixes (with null checks) for multi-threading environments is not a good idea.
An alternative workaround that you can try on your side is to dispose the map before closing the window. For example:
if (_openWindows.Count > 0 && _openWindows.Count % 2 == 0) { var toClose = _openWindows.FirstOrDefault(); TypeDescriptor.Refresh(toClose.radMap); toClose.radMap.Dispose(); toClose?.Close(); _openWindows.Remove(toClose); }
Additionally, you can try waiting one more layout pass before opening the new window:
Dispatcher.BeginInvoke(new Action(() => { WindowWithMap wwm = new WindowWithMap(); wwm.MapPointInfo = new MapPointData { Lat = 0, Lon = 0 }; _openWindows.Add(wwm); wwm.Show(); }));
I have received a new crash dump from my customer that contains slightly more information. On the off chance this helps identify anything, I have included it below. Unfortunately I still do not have any steps to reproduce the crash.
CoreCLR Version: 4.700.22.30802.NET Core Version: 3.1.27
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException: Object reference not set to an instance of an object.
at Telerik.Windows.Controls.Map.TilePresenter.MapSourceInitializeCompleted(Object sender, EventArgs e)
at Telerik.Windows.Controls.Map.TiledMapSource.RaiseInitializeCompleted()
at Telerik.Windows.Controls.Map.BingRestTileMapSource.ImageryService_GetImageryMetadataCompleted(Object sender, DownloadStringCompletedEventArgs e)
at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
at System.Net.WebClient.<StartAsyncOperation>b__78_2(Object arg)
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)
--- End of stack trace from previous location where exception was thrown ---
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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run()
Thank you for the new information. I've checked this but I am afraid that it doesn't tell anything new about the issue.
Martin,
What is listening for the TilePresenter.MapSourceInitializeCompleted event that could be throwing a null reference exception? That is not an event that I can find to subscribe to from any of the classes I have access to, so I have no way of identifying any potential causes, which is greatly hampering my ability to fix this issue for our customer.
Sorry for the delay. The MapSourceInitializeCompleted is a handler for the InitializeCompleted event of the underlying TiledMapSource. To subscribe for this event, you can create a custom map provider, that derives from the one you are using. And then, you can use the MapSources to get all supported TiledMapSources of the provider and subscribe to their InitializeCompleted events.
public class CustomBingRestMapProvider : BingRestMapProvider { public CustomBingRestMapProvider() : base() { // here you may need to get another map source or subscribe all sources to the event handler var source1 = this.MapSources.Values.ElementAt(0); source1.InitializeCompleted += Source1_InitializeCompleted; } private void Source1_InitializeCompleted(object sender, EventArgs e) { } }