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?
Ok, thanks. I shall ruminate this async business over my weekend.
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:
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...
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?
...also which Http Client implementation have you configured your app to use? (some of them are rather buggy). See Project properties -> Android Options -> Advanced.
-That error code is 403.
HTTP client is "Android."
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:
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?
More info, let me know if you need the entire trace:
This is at the same breakpoint pictured previously.
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.
> 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: