System Information
- Windows 10 Technical Preview (build 9926)
- Visual Studio Community 2013
Attempting to debug on:- [AT&T] Lumia 635 (Windows 10 Technical Preview for phones build 9941 w/ Lumia Cyan)
- [AT&T] Lumia 1520 (Windows Phone 8.1 with Lumia Denim and PfD)
- [Unlocked] BLU Win Jr (Windows Phone 8.1 with PfD)
- [Verizon] Lumia Icon (Windows Phone 8.1 with Lumia Denim and PfD)
I trying to get location services working in my app. Previously, I had Visual Studio throw the error. It was an ArgumentException
with the message "Use of undefined keyword value 1 for event TaskScheduled in async
". Googling didn't turn up any solutions.
Here is the code:
Geolocator Locator = new Geolocator();
Geoposition Position = await Locator.GetGeopositionAsync();
Geocoordinate Coordinate = Position.Coordinate;
When I could get the error to be thrown, the exception was thrown on the 2nd or 3rd line in the sample above. I simplified the original code to try and fix it, but this is the original:
Geolocator Locator = new Geolocator();
Geocoordinate Coordinate = (await Locator.GetGeopositionAsync()).Position.Coordinate;
The entire app works when debugging, but crashes almost instantaneously otherwise.
This is a Windows 8.1 Universal project, focusing on the phone project.
Thanks in advance
EDIT: As requested, here is the full method:
private static bool CheckConnection()
{
ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
return internet;
}
public static async Task<double> GetTemperature(bool Force)
{
if (CheckConnection() || Force)
{
Geolocator Locator = new Geolocator();
await Task.Yield(); //Error occurs here
Geoposition Position = await Locator.GetGeopositionAsync();
Geocoordinate Coordinate = Position.Coordinate;
HttpClient Client = new HttpClient();
double Temperature;
Uri u = new Uri(string.Format("http://api.worldweatheronline.com/free/v1/weather.ashx?q={0},{1}&format=xml&num_of_days=1&date=today&cc=yes&key={2}",
Coordinate.Point.Position.Latitude,
Coordinate.Point.Position.Longitude,
"API KEY"),
UriKind.Absolute);
string Raw = await Client.GetStringAsync(u);
XElement main = XElement.Parse(Raw), current_condition, temp_c;
current_condition = main.Element("current_condition");
temp_c = current_condition.Element("temp_C");
Temperature = Convert.ToDouble(temp_c.Value);
switch (Memory.TempUnit)
{
case 0:
Temperature = Convertions.Temperature.CelsiusToFahrenheit(Temperature);
break;
case 2:
Temperature = Convertions.Temperature.CelsiusToKelvin(Temperature);
break;
}
return Temperature;
}
else
{
throw new InvalidOperationException("Cannot connect to the weather server.");
}
}
EDIT 2: I've asked for help on Twitter, and received a reply asking for a repro project. I recreated the major portion of the original app, but I could not get the error. However, errors may occur for you so here's the project.
EDIT 3: If it helps at all, here are the exception details:
System.ArgumentException occurred
_HResult=-2147024809
_message=Use of undefined keyword value 1 for event TaskScheduled.
HResult=-2147024809
IsTransient=false
Message=Use of undefined keyword value 1 for event TaskScheduled.
Source=mscorlib
StackTrace:
at System.Diagnostics.Tracing.ManifestBuilder.GetKeywords(UInt64 keywords, String eventName)
InnerException:
Geoposition Position = await Task.Run(() => Locator.GetGeopositionAsync());
– Stibineawait Task.Yeild(); Geocoordinate Coordinate = (await Locator.GetGeopositionAsync()).Position.Coordinate;
Does it crash afterTask.Yeild()
or afterawait Locator.GetGeopositionAsync()
? – StibineTask.Yield()
andawait Locator.GetGeopositionAsync()
. My guess is that it crashes atTask.Yield()
because none of the dialogs popup. Again, it only does this while not debugging. Thanks btw, haha :P – Sensuousawait
beforeTask.Yield()
, see if it makes any difference. Also what I meant is, what's the root method of the call chain leading toGetTemperature
. Is it anasync void
UI event handler, or something likeOnLaunched
? Also, what do you see if you addDebug.WriteLine(new { SynchronizationContext.Current })
to the beginning ofGetTemperature
? – Stibineawait
in my code, but forgot to add it in the snippet. The stack starts fromprotected override async void OnNavigatedTo(NavigationEventArgs e)
, to a method that eventually callsGetTemperature(false)
(awaited). As forDebug.WriteLine(new { SynchronizationContext.Current })
, it prints{ Current = System.Threading.WinRTSynchronizationContext }
. – Sensuous