Bug 21455 - Geocoder does not work from background thread in Windows Phone project.
Summary: Geocoder does not work from background thread in Windows Phone project.
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.1.1
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-07-18 22:59 UTC by Eric Grover
Modified: 2015-02-02 01:53 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Eric Grover 2014-07-18 22:59:50 UTC
In my view model, if I run:

var coder = new Geocoder();

var partnerPosition = (await coder.GetPositionsForAddressAsync(partner.Address)).FirstOrDefault();

I get a cross-thread execution exception. If I try to wrap the code in Device.BeginInvokeOnMainThread, it executes but returns no results. I can successfully call the above code in the constructor of a Page, and it executes correctly.
Comment 1 Eric Maupin 2014-07-21 11:33:08 UTC
This is a limitation of the underlying platform. However, given that the method returns a task, there is no need to initiate it on a separate thread to begin with.
Comment 2 Eric Grover 2014-07-21 11:35:56 UTC
I am not initiating it on a separate thread.  I get the cross-thread exception when I make the call from a method in my view model that is being called from the OnBindingContextChanged event of my page.
Comment 3 Jason Smith [MSFT] 2015-02-02 01:53:11 UTC
The exception is coming from the underlying platform. I have double checked it throws this exception if you call from a thread, please validate your code is indeed on the main thread. (Setting the BindingContext from a thread could for example trigger OnBindingContextChanged on a thread).

Please re-open if you can provide a stacktrace of the exception being in the UI thread.