Microsoft Band SDK Sensors.Windows示例异常

时间:2015-06-03 05:44:46

标签: c# .net windows-store-apps microsoft-band

当我尝试在Windows 10计算机上运行Microsoft Band SDK(1.3.10417.1)的Sensors.Windows示例项目时,我遇到以下异常:

System.ArgumentException: Value does not fall within the expected range.
   at Windows.ApplicationModel.Store.CurrentApp.get_AppId()
   at Microsoft.Band.StoreApplicationPlatformProvider`2.GetApplicationIdAsync(CancellationToken token)
   at Microsoft.Band.BandClient.StartOrAwakeStreamingSubscriptionTasks()
   at Microsoft.Band.BandClient.SensorSubscribe(SubscriptionType type)
   at Microsoft.Band.Sensors.BandSensorBase`1.<>c__DisplayClass4.<StartReadingsAsync>b__3()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Band.Sensors.BandSensorBase`1.<StartReadingsAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at PunchingBand.Models.PunchingModel.<Connect>d__48.MoveNext()

它看起来像是在抛出异常,因为SDK使用CurrentApp根据CurrentAppSimulator上的备注部分here,如果该应用无法使用CurrentApp并未在Windows应用商店中列出。

如果SDK需要访问CurrentApp,我该如何在开发应用时让它工作?我不能在预编译的程序集中将CurrentAppSimulator与{{1}}交换。

1 个答案:

答案 0 :(得分:1)

更新:这已在Microsoft Band SDK版本1.3.10702中修复。如果可能升级到该版本,否则使用下面的黑客。

在使用.NET Reflector进行一些调查之后,我发现了一个让它工作的黑客攻击。只需在currentAppId上设置名为BandClient的私有字段,SDK就不会尝试从CurrentApp获取该字段。在建立与客户端的连接之后,在尝试流式传输任何传感器之前,运行以下命令:

using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
    Type.GetType("Microsoft.Band.BandClient, Microsoft.Band")
        .GetRuntimeFields()
        .First(field => field.Name == "currentAppId")
        .SetValue(bandClient, Guid.NewGuid());

请确保包含System.LinqSystem.Reflection的使用。这显然是一个非常hacky的解决方法,所以希望它在未来的Band SDK版本中得到解决。