0

I tried to write a desktop app which communicates with Bluetooth LE (using VS2017). It means I need UWP API and I tried two solutions. One from this sample and other using UwpDesktop. Both work fine and I can advertise BLE and get responses. But if I try to get BluetoothLEDevice object via async FromBluetoothAddressAsync(ulong arg) with await, nothing happens. The app just stops at this line without exception. Here is my code:

private async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
    {
        ulong bluetoothAddress = eventArgs.BluetoothAddress;

        BluetoothLEAdvertisementType advertisementType = eventArgs.AdvertisementType;
        IList<Guid> serviceUuids = eventArgs.Advertisement.ServiceUuids;
            
        for (int i = 0; i < serviceUuids.Count; i++)
        {
            string stringUuid = serviceUuids[i].ToString();
            if (serviceUuids[i].ToString().Equals(stringID))
            {
                BluetoothLEDevice device = null;
                try
                {
                    device = await BluetoothLEDevice.FromBluetoothAddressAsync(bluetoothAddress);//here stops the program, no exception
                }
                catch (Exception ex)
                {
                    throw;
                }
                GattDeviceService service = device.GetGattService(serviceUuids[i]);
            }
        }
}

I tried this and this solutions, nothing helps.

EDIT: The Output windows shows repeatedly this exception:

[Inspector] Error preparing project for inspection: System.NullReferenceException: Object reference not set to an instance of an object.
   at Xamarin.VisualStudio.Inspector.ProjectExtensions.GetProjectFlavor(IAdaptable`1 adaptableProj) in C:\d\lanes\4699\fec6f88f\source\xamarinvs\src\Features\VisualStudio.Inspector\Vsix\Extensions\ProjectExtensions.cs:line 62
   at Xamarin.VisualStudio.Inspector.VSAgentExecutionTarget..ctor(Project proj) in C:\d\lanes\4699\fec6f88f\source\xamarinvs\src\Features\VisualStudio.Inspector\Vsix\VSAgentExecutionTarget.cs:line 42
   at Xamarin.VisualStudio.Inspector.VSInspectorSession.CreateAgentExecutionTarget() in C:\d\lanes\4699\fec6f88f\source\xamarinvs\src\Features\VisualStudio.Inspector\Vsix\VSInspectorSession.cs:line 84
   at Xamarin.Interactive.IdeSupport.InspectorSession.Prepare() in C:\d\lanes\4699\fec6f88f\source\xamarinvs\External\inspector-ide-integration\Xamarin.Interactive.IdeSupport\InspectorSession.cs:line 95
   at Xamarin.VisualStudio.Inspector.XamarinInspectorPackage.RefreshInspectorSession() in C:\d\lanes\4699\fec6f88f\source\xamarinvs\src\Features\VisualStudio.Inspector\Vsix\XamarinInspectorPackage.cs:line 136
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Alexander Tumanin
  • 1,638
  • 2
  • 23
  • 37

0 Answers0