系统信息
- Windows 10 技术预览版(内部版本 9926)
- Visual Studio 社区 2013
尝试调试:
-
[美国电话电报公司]Lumia 635(Windows 10 技术预览版,适用于版本 9941 的手机,带有 Lumia Cyan)
-
[美国电话电报公司]Lumia 1520(带有 Lumia Denim 和 PfD 的 Windows Phone 8.1)
-
[解锁]BLU Win Jr(带 PfD 的 Windows Phone 8.1)
-
[威瑞森]Lumia 图标(带有 Lumia Denim 和 PfD 的 Windows Phone 8.1)
我试图让位置服务在我的应用程序中运行。以前,我让 Visual Studio 抛出错误。这是一个ArgumentException
与消息“Use of undefined keyword value 1 for event TaskScheduled in async
“。谷歌搜索没有找到任何解决方案。
这是代码:
Geolocator Locator = new Geolocator();
Geoposition Position = await Locator.GetGeopositionAsync();
Geocoordinate Coordinate = Position.Coordinate;
当我可以抛出错误时,异常在上面示例中的第二行或第三行抛出。
我简化了原始代码来尝试修复它,但这是原始代码:
Geolocator Locator = new Geolocator();
Geocoordinate Coordinate = (await Locator.GetGeopositionAsync()).Position.Coordinate;
整个应用程序在调试时可以正常工作,但在其他情况下几乎会立即崩溃。
这是一个 Windows 8.1 通用项目,专注于手机项目。
提前致谢
编辑:根据要求,这是完整的方法:
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 在 Twitter 上寻求帮助 https://twitter.com/devgregw/status/564804691695919104, and 收到回复 https://twitter.com/WinDevMatt/status/564872023139024897要求重现项目。我重新创建了原始应用程序的主要部分,但我无法收到错误。但是,您可能会遇到错误.
编辑 3:如果有帮助的话,这里是异常详细信息:
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: