ThinkGeo.com    |     Documentation    |     Premium Support

Task cancelled exception for ThinkGeo.Core.WebBasedAsyncLayer

Hi, we were using ThinkGeo.UI.Maui 14.2.2 for quite some time now and were not facing any issues but after upgrading to ThinkGeo.UI.Maui 14.3.2 or 14.3.3 current stable release we are facing issue with ThinkGeo.Core.WebBasedAsyncLayer. We are loading google map layer in WebBasedTileOverlay as below.

var layerOverlay = new WebBasedTileOverlay();
GoogleMapsAsyncLayer googleLayer = new GoogleMapsAsyncLayer(GoogleMapApiKey);
layerOverlay.WebBasedLayer = googleLayer;

when we pinch zoom in or zoom out with two fingers and while tiles are loading we again instantly zoom out its crashing the application and throwing below error.

Message: The request timed out. A task was canceled.
Exception type: System.Threading.Tasks.TaskCanceledException
Failed method: ThinkGeo.Core.WebBasedAsyncLayer+skA=.MoveNext

This issue is happening only on iOS device with ThinkGeo.UI.Maui 14.3.2 or 14.3.3 I don’t face this issue on android devices. Also same issue wont happen when I uses ThinkGeo.UI.Maui 14.2.2.

below is detailed stack trace

System.TimeoutException:
at System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStream+d__14.MoveNext (Microsoft.iOS, Version=18.5.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065: /Users/builder/azdo/_work/2/s/macios/src/Foundation/NSUrlSessionHandler.cs:1390)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Threading.Tasks.ValueTask1[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].get_Result (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1+ConfiguredValueTaskAwaiter[[System.Int32, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetResult (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.IO.Stream+<g__Core|27_0>d.MoveNext (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)

Hi Patrick,

TaskCanceledException is how .NET deals with the cancellation and in this case, you can just safely ignore it. In v14.3 we by default throw the layer exceptions for easier debugging, you can just do googleLayer.DrawingExceptionMode = DrawingExceptionMode.DrawException (it’s DrawAndThrowException by default)

Thanks,
Ben

Hi Ben,

Issue here is it just crashes whole application and in crash analytics I get this exception so not sure how can I handle this one I already tried setting DrawingExceptionMode.DrawException but still application getting crashed. if I revert back to older version I don’t face this issue.

Hi Patrick,

We dug in and found it’s a bug that the layer doesn’t respect DrawingExceptionMode when calling DownloadImageAsync. It will be fixed in the future versions and for now, you can create a custom Google layer like following to work around:

public class MyGoogleMapsAsyncLayer : GoogleMapsAsyncLayer
{
    public MyGoogleMapsAsyncLayer()
    {}

    protected override Task<byte[]> DownloadImageAsyncCore(double width, double height, double scaleFactor, RectangleShape extent,
        GeographyUnit mapUnit, CancellationToken cancellationToken)
    {
        try
        {
            return base.DownloadImageAsyncCore(width, height, scaleFactor, extent, mapUnit, cancellationToken);
        }
        catch (Exception e)
        {
            // eat the exception and return null. 
            return null;
        }
    }
}

Thanks,
Ben