Select to view content in your preferred language

Route does not draw on first attempt, but does subsequently

2338
20
05-30-2019 10:22 AM
ITS_JohnColaneri
New Contributor

env:

Xamarin Android on Visual Studio 17 - min API level 21, target - 27, TLS 1.2 settings/ testing on Samsung Galaxy S8 device

I've been struggling for some time with an issue where: when loading a map and attempting to draw a route, the route draw fails (just doesn't draw it - pretty sure the route-solve is not throwing any errors). If I back-up in the GUI, and initiate the map/route draw again, the subsequent attempts succeed.

I "back-burner"-ed this bug for a couple months to work on other aspects of the app. I observed that the map was "Loaded," but not drawn before the route-solve started, so I thought "Ah ha!" I've switched the code around to wait for the "DrawStatus.Completed" event instead, (and made it quasi-idempotent with a bool switch so the route only gets initiated once). I'm still getting the same result though. First time through, no route. All subsequent attempts are fine (if a little sluggish).

Can anyone help with this?

0 Kudos
20 Replies
ITS_JohnColaneri
New Contributor

Ok, thanks. I shall ruminate this async business over my weekend.

0 Kudos
ITS_JohnColaneri
New Contributor

So, the exception is getting thrown on this line in the DoRoute method at the top of the try block:

      RouteTask solveRouteTask = await RouteTask.CreateAsync(
         new Uri("https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"));

AggregateException.InnerException:

MemoryStream.CopyToAsync (System.IO.Stream destination, System.Int32 bufferSize, System.Threading.CancellationToken cancellationToken)

Message:

"Cannot access a closed Stream."

ObjectName:

""

Not sure how to interpret that as I don't know what is going on inside RouteTask.CreateAsync...

0 Kudos
dotMorten_esri
Esri Notable Contributor

That error doesn't doesn't look good. Is there a stack trace on that exception that might give us a little more insight into where it's going wrong?
And can you access that URL from the browser of that device?

0 Kudos
dotMorten_esri
Esri Notable Contributor

...also which Http Client implementation have you configured your app to use? (some of them are rather buggy). See Project properties -> Android Options -> Advanced.

0 Kudos
ITS_JohnColaneri
New Contributor
  • Esri.ArcGISRuntime.Http
    ArcGISHttpClientHandler+ArcGISClientHandlerInternal+<>c__DisplayClass14_1.<SendAsync>b__0 (System.Threading.Tasks.Task`1[TResult] t)
  • System.Threading.Tasks
    ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke ()
  • System.Threading.Tasks
    Task.Execute ()
  • Esri.ArcGISRuntime.Http
    ArcGISHttpClientHandler+ArcGISClientHandlerInternal+<SendAsync>d__14.MoveNext ()
  • System.Runtime.CompilerServices
    TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter`1[TResult].GetResult ()
  • Esri.ArcGISRuntime.Http
    ArcGISHttpClientHandler+ArcGISClientHandlerInternal+<SendAsync>d__14.MoveNext ()
  • System.Runtime.CompilerServices
    TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult ()
  • System.Net.Http
    HttpClient+<SendAsyncWorker>d__49.MoveNext ()
  • System.Runtime.CompilerServices
    TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult ()
  • Esri.ArcGISRuntime.Internal
    RequestRequiredHandler+<IssueRequestAndRespond>d__14.MoveNext ()
  • System.Runtime.CompilerServices
    TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult ()
  • Esri.ArcGISRuntime.Tasks.NetworkAnalysis
    RouteTask+<CreateAsync>d__11.MoveNext ()
  • System.Runtime.CompilerServices
    TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task)
  • System.Runtime.CompilerServices
    TaskAwaiter`1[TResult].GetResult ()
  • gov.ca.fire.CMIP.Fragments
    CMIPEsriMapFragment+<DoRoute>d__33.MoveNext () C:\Temp\CMIP.Esri\CMIP\CMIP\Fragments\CMIPEsriMapFragment.cs:521

-That error code is 403.

HTTP client is "Android."

0 Kudos
ITS_JohnColaneri
New Contributor

In between when this gets called, and when it throws the exception, CreateCredentialAsync gets called:

      RouteTask solveRouteTask = await RouteTask.CreateAsync(
         new Uri("https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"));

I can see that it is actually getting a token, but by the time it gets around to completing this RouteTask.CreateAsync method, the Exception gets thrown:

0 Kudos
ITS_JohnColaneri
New Contributor

Is there no one that can help with this problem? All the stuff that I have written appears to be processing correctly, but the black-box Esri stuff returns an exception. Where do I go from here?

0 Kudos
ITS_JohnColaneri
New Contributor

More info, let me know if you need the entire trace:

This is at the same breakpoint pictured previously.

0 Kudos
KyleGruber
Occasional Contributor II

John,

Here's a shot in the dark suggestion, have you tried making the calls synchronous instead of asynchronous to see if it makes a difference?

Change all await calls to .GetAwaiter().GetResult()

So if you're doing await RouteTask.GetRouteAsync(), it would change to RouteTask.GetRouteAsync().GetAwaiter().GetResult().

Just to clarify, I'm not suggesting this as a solution to the problem (I would never advocate running things synchronously on the UI layer), but if it helps it would at least isolate the issue to the async/await functionality.

0 Kudos
dotMorten_esri
Esri Notable Contributor

 have you tried making the calls synchronous instead of asynchronous to see if it makes a difference?

Please don't ever do this in a multi-threaded application. You could deadlock your application.

Just to clarify, I'm not suggesting this as a solution to the problem

:thumbs-up:

0 Kudos