Is it possible to use the Microsoft Band SDK from within a Windows Runtime Component? GetBandsAsync
works, but it fails when connecting using:
IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])
I am using Microsoft Band SDK 1.3.10518. I have added rfcomm capabilities to the app package manifest and I get a the following exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime.InteropServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.Band.MarshalUtils.GetBytes[T](T& structure, Byte[] resultArray, Int32 offset)
at Microsoft.Band.BandClient.CheckFirmwareSdkBit(FirmwareSdkCheckPlatform platform, Byte reserved)
at Microsoft.Band.BandClientManager.<ConnectAsync>d__2.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 BandController.Band.<StartRemoteControlAsync>d__5.MoveNext()} System.Exception {System.IO.FileNotFoundException}
To reproduce the error, this is what I have done:
- In Visual Studio create a new Blank App (Windows Phone Silverlight)
- Add a button to the app (let's say "Test band") and add a handler for Tap event
- Add a Windows Runtime Component (Windows Phone) to the solution, call it BandTest, the namespace BandWrapper
- Add Microsoft Band SDK to the BandWrapper project
- Add rfcomm and proximity capabilities in the Package.appxmanifext of the Silverlight project (for the BandWrapper rfcomm is added by Microsoft Band SDK installer)
Implement the test button handler as follows:
private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e) { BandWrapper.BandTest wrapper = new BandWrapper.BandTest(); wrapper.TestBand(); }
And in the runtime component copy from the SDK sample the following, in the
public async void TestBand()
method:try { // Get the list of Microsoft Bands paired to the phone/tablet/PC. IBandInfo[] pairedBands = await BandClientManager.Instance.GetBandsAsync(); if (pairedBands.Length < 1) { //this.viewModel.StatusMessage = "This sample app requires a Microsoft Band paired to your device. Also make sure that you have the latest firmware installed on your Band, as provided by the latest Microsoft Health app."; return; } // Connect to Microsoft Band. using (IBandClient bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])) { // We'll create a Tile that looks like this: // +--------------------+ // | MY CARD | // | ||||||||||||||||| | // | 123456789 | // +--------------------+ // First, we'll prepare the layout for the Tile page described above. TextBlock myCardTextBlock = new TextBlock() { Color = Colors.Blue.ToBandColor(), ElementId = 1, // the Id of the TextBlock element; we'll use it later to set its text to "MY CARD" Rect = new PageRect(0, 0, 200, 25) };
...
If at the step 1. above, I create an Windows Phone app (not Silverlight) the execution of the test method goes up to
await bandClient.TileManager.AddTileAsync(myTile);
and there it fails with:
System.TypeLoadException: Could not find Windows Runtime type 'Windows.Foundation'.
at System.StubHelpers.WinRTTypeNameConverter.GetTypeFromWinRTTypeName(String typeName, Boolean& isPrimitive)
at System.StubHelpers.SystemTypeMarshaler.ConvertToManaged(TypeNameNative* pNativeType, Type& managedType)
at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
at Microsoft.Band.StoreApplicationPlatformProvider`2.<>c__DisplayClassd`1.<GetConsentAsync>b__a()
--- 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.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Band.StoreApplicationPlatformProvider`2.<GetConsentAsync>d__f`1.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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Microsoft.Band.BandClient.<>c__DisplayClass6f.<<AddTileAsync>b__6c>d__71.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 BandWrapper.BandTest.<TestBand>d__5.MoveNext()} System.Exception {System.TypeLoadException}