当我试图在我的Windows10机器上运行Microsoft的Sensors.Windows示例项目(1.3.10417.1)时,我得到以下异常:
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,根据备注部分,这里 on CurrentAppSimulator是不可能的,如果应用程序不在Windows中列出的话。
如果SDK需要访问CurrentApp,那么在开发我的应用程序时,如何才能让它工作呢?在预编译的程序集中,我不可能将CurrentApp与CurrentAppSimulator交换。
发布于 2015-06-05 05:16:01
更新:在Microsoft版本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的使用。这显然是一个非常麻烦的解决办法,因此希望它能在今后的Band发行版中得到解决。
https://stackoverflow.com/questions/30611731
复制相似问题