1
votes

When I try to run the Sensors.Windows sample project for the Microsoft Band SDK (1.3.10417.1) on my Windows 10 machine I get the following exception:

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()

It looks like it's throwing the exception because the SDK uses the CurrentApp which according to the remarks section here on CurrentAppSimulator isn't possible if the app isn't listed in the Windows Store.

If the SDK needs access to CurrentApp how can I get this to work while developing my app? It's not like I can swap CurrentApp with CurrentAppSimulator in a pre-compiled assembly.

1

1 Answers

1
votes

Update: This was fixed in Microsoft Band SDK version 1.3.10702. If possible upgrade to that version otherwise use the hack below.

I figured out a hack to get this working after some investigation with .NET Reflector. Just set a private field called currentAppId on the BandClient and the SDK won't attempt to get it from CurrentApp. Right after a connection to the client is made and before attempting to stream any sensors run the following:

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());

Be sure to include a using for System.Linq and System.Reflection. This is obviously a very hacky workaround so hopefully it's resolved in a future release of the Band SDK.