I am developing a Windows phone 8.1 app which connects with a Microsoft Band to send some notification. I need to perform some background tasks, so I have added a Windows Runtime Component project.
I am sending the notification from the background task i.e. from the Runtime component project. But I am getting an error. The error is as follows:
Error: System.TypeInitializationException: The type initializer for 'Microsoft.Band.Store.StoreResources' threw an exception. ---> System.Exception: Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) at Windows.UI.Xaml.Application.get_Current() at Microsoft.Band.Store.StoreResources..cctor() --- End of inner exception stack trace --- at Microsoft.Band.Store.StoreResources.get_RfComm_FromId_ReturnedNull() at Microsoft.Band.Store.BluetoothTransport.GetTransport(RfcommDeviceService service, ILoggerProvider loggerProvider, UInt16 maxConnectAttempts) at Microsoft.Band.Store.BluetoothTransport.<>c__DisplayClass1.b__0() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()
As said in an answer in this Question that the foreground app should not try to connect to the band while the background app is trying to connect.
- My foreground app is not trying to connect nor does have any connection with the band.
I think the error is for problems in connecting to Bluetooth, because I have debugged and found out the location of the error:
public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
try
{
Debug.WriteLine("Task Triggered " + DateTime.Now);
taskInstance.Canceled += (s, e) => { };
taskInstance.Progress = 0;
// Get the list of Microsoft Bands paired to the phone.
var pairedBands = await BandClientManager.Instance.GetBandsAsync();
if (pairedBands.Length < 1)
{
Debug.WriteLine(
"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;
}
// This is the line I am getting the error
using (var bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0]))
{
Debug.WriteLine("Tile creation started");
My band's Bluetooth is connecting fine with Microsoft Health app, so I suppose there is nothing wrong with Bluetooth of my phone and band.
My Package.appmanifest for Foreground app is as follows:
Package.appmanifest for Background Task ( Windows Runtime Component project):
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Capabilities>
<DeviceCapability Name="bluetooth.rfcomm" xmlns="http://schemas.microsoft.com/appx/2013/manifest">
<Device Id="any">
<!-- Used by the Microsoft Band SDK -->
<Function Type="serviceId:A502CA9A-2BA5-413C-A4E0-13804E47B38F" />
<!-- Used by the Microsoft Band SDK -->
<Function Type="serviceId:C742E1A2-6320-5ABC-9643-D206C677E580" />
</Device>
</DeviceCapability>
So what can be the possible issue? Can you provide a solution or a work-around to this problem?