Plugin.BluetoothBLE Nuget package integration Error in macOs and iOS.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By o.fawzi

Hi all,
I have tried to integrate BluetoothBLE nuget package ( NuGet Gallery | Plugin.BluetoothLE 6.3.0.19 ) to the C# project so I can connect the macOS and iOS apps to BLEs.
but actually after integration Godot Logcat is throwing error while building as follow:

E 0:00:00.910   Plugin.BluetoothLE.IAdapter Plugin.BluetoothLE.CrossBleAdapter.get_Current(): System.ArgumentException: [Plugin.BluetoothLE] No platform plugin found.  Did you install the nuget package in your app project as well?
  <C++ Error>   Unhandled exception
  <C++ Source>  D:\a\1\s\Plugin.BluetoothLE\CrossBleAdapter.cs:28 @ Plugin.BluetoothLE.IAdapter Plugin.BluetoothLE.CrossBleAdapter.get_Current()()
  <Stack Trace> CrossBleAdapter.cs:28 @ Plugin.BluetoothLE.IAdapter Plugin.BluetoothLE.CrossBleAdapter.get_Current()()
                BLEScanner.cs:18 @ void BLEScanner._bind()()
                BLEScanner.cs:14 @ void BLEScanner._Ready()()

So I have exported the project to iOS platform adits also throwing the following error:

2020-09-03 11:37:33.782023+0200 Godot_Sonic[57040:12159108] Mono: The following assembly referenced from .mono/assemblies/Debug/Playground.dll could not be loaded:
     Assembly:   Plugin.BLE    (assemblyref_index=3)
     Version:    1.0.0.0
     Public Key: (none)
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/Users/Osama/Library/Developer/CoreSimulator/Devices/0DD532EF-C373-4626-9A6B-853F1D4ED729/data/Containers/Bundle/Application/6933DB0F-5F4E-4A06-BB15-B347DB6F821B/Godot_Sonic.app/.mono/assemblies/Debug/).
2020-09-03 11:37:33.782598+0200 Godot_Sonic[57040:12159108] Mono: The following assembly referenced from .mono/assemblies/Debug/Playground.dll could not be loaded:
     Assembly:   Plugin.BLE    (assemblyref_index=3)
     Version:    1.0.0.0
     Public Key: (none)
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/Users/Osama/Library/Developer/CoreSimulator/Devices/0DD532EF-C373-4626-9A6B-853F1D4ED729/data/Containers/Bundle/Application/6933DB0F-5F4E-4A06-BB15-B347DB6F821B/Godot_Sonic.app/.mono/assemblies/Debug/).
2020-09-03 11:37:33.783412+0200 Godot_Sonic[57040:12159108] Mono: Failed to load assembly Playground[0x600003605700].
2020-09-03 11:37:33.843956+0200 Godot_Sonic[57040:12159108] 
Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Plugin.BLE, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
File name: 'Plugin.BLE, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
  at BLEScanner._Ready () [0x00001] in <cf622ec8a63c4f41ab1b2c688b6e3b37>:0

this is the piece of code in C# class:

using Godot;
using System;
using Plugin.BluetoothLE;

public class BLEScanner : Spatial
{

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        _bind();
    }

    void _bind() {
        CrossBleAdapter.Current.Scan().Subscribe(discoveredTag => {
            GD.Print("new tag discovered:",discoveredTag);
        });
    }
}

Side Note:
I have tried several things like:

  • Removing the BluetoothBLE nuget package and run the project and its working fine in both MacOS and iOS.
  • integrating Newtonsoft.Json nuget with print out a simple serialisation example and worked fine.
  • tried different BLE nugets like plugin.Ble and same previous error raised in iOS (Assembly: Plugin.BLE.Abstractions) but different in macOS as follow:
E 0:00:01.076   Plugin.BLE.Abstractions.Contracts.IBluetoothLE Plugin.BLE.CrossBluetoothLE.get_Current(): System.NotImplementedException: This functionality is not implemented in the portable version of this assembly.  You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
  <C++ Error>   Unhandled exception
  <C++ Source>  E:\Projects\xamarin-bluetooth-le\Source\Plugin.BLE\CrossBluetoothLE.cs:23 @ Plugin.BLE.Abstractions.Contracts.IBluetoothLE Plugin.BLE.CrossBluetoothLE.get_Current()()
  <Stack Trace> CrossBluetoothLE.cs:23 @ Plugin.BLE.Abstractions.Contracts.IBluetoothLE Plugin.BLE.CrossBluetoothLE.get_Current()()
                BLEScanner.cs:13 @ void BLEScanner._bind()()
                BLEScanner.cs:9 @ void BLEScanner._Ready()()

C# code:

using Godot;
using System;
using Plugin.BLE;

public class BLEScanner : Spatial
{
    public override void _Ready()
    {
        _bind();
    }

    void _bind() {
        var ble = CrossBluetoothLE.Current;
        var state = ble.State;
        GD.Print("current bluetooth state",state);

    }
}

And i have tried to include plugin.ble.Abstractions manually into the .mono/assemblies/debug & release, but still same error exist

  • in any case C# project is building successfully.
  • tried to clean all and rebuild all in C# project.

Thanks in advance.

Did you ever get this working? I’m building something in Godot that needs to connect to BLE sensors from iPadOS and Android.

Thanks in advance.

IaBUK | 2022-09-02 02:26