系统信息
- Windows 10技术预览版(版本9926)
- Visual Studio Community 2013
尝试在以下设备上进行调试:- [AT&T] Lumia 635 (Windows 10手机技术预览版,版本9941,带有Lumia Cyan)
- [AT&T] Lumia 1520 (Windows Phone 8.1,带有Lumia Denim和PfD)
- [Unlocked] BLU Win Jr (Windows Phone 8.1,带有PfD)
- [Verizon] Lumia Icon (Windows Phone 8.1,带有Lumia Denim和PfD)
我试图让我的应用程序能够使用位置服务。 以前,我在Visual Studio中出现了错误。 它是一个带有消息“Use of undefined keyword value 1 for event TaskScheduled in async
”的ArgumentException
。 搜索引擎没有提供任何解决方案。
这是我的代码:
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.");
}
}
编辑2: 我已在Twitter上寻求帮助,并收到回复要求提供可重现项目。我重新创建了原始应用程序的主要部分,但我无法获得该错误。但是,您可能会遇到错误,因此这是该项目。
编辑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:
Task.Yield()
和await Locator.GetGeopositionAsync()
之后弹出。我猜测它在Task.Yield()
处崩溃,因为没有任何对话框弹出。再次说明,只有在非调试状态下才会出现这种情况。顺便说一句,谢谢哈 :P - Greg Whatley