当我尝试在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}}交换。
答案 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.Linq
和System.Reflection
的使用。这显然是一个非常hacky的解决方法,所以希望它在未来的Band SDK版本中得到解决。