Hello guys, am trying to access the windows in-built adapter from C# library known as Bluetooth LE (Low Energy). I have installed the nuget package and when I try to run my code, I get the error that
Unhandled exception. System.ArgumentException: [Plugin.BluetoothLE] No platform plugin found. Did you install the nuget package in your app project as well?. I have tried looking online to see if there is a GATTServer instance that needs to be started but did not succeed. Please help me access the adapter correctly without this exception being thrown. Here is the C# code am trying to use

public class BTClient
    {
        //define the adapter
        static IAdapter adapter;
        //declare  variable to hold the UUID of a device
        string UUID;
        public BTClient()
        {
            //assign the adapter on constructor exit
            //this adapter allows usage across various platforms
            adapter = CrossBleAdapter.Current;
        }
        /// <summary>
        /// the method below is for discovering bluetooth devices
        /// nearby
        /// </summary>
        /// <returns></returns>
      [DllExport("devices", CallingConvention = CallingConvention.Cdecl),ComVisible(true)]
        public static List<Plugin.BluetoothLE.IDevice> DiscoverDevices()
        {
            IGattServer server = (IGattServer)CrossBleAdapter.Current.CreateGattServer();
            server.CreateService(new Guid(), true);
             var devices = new List<Plugin.BluetoothLE.IDevice>();
            var scanner = CrossBleAdapter.Current.Scan().Subscribe(scanResult =>
             {
                 devices.Add(scanResult.Device);
             });
            return devices;
        }
}

class Solution{
   static void Main(){
            List<IDevice> devices = new List<IDevice>();
            devices = BTClient.DiscoverDevices();
            foreach(var device in devices){
             Console.WriteLine(device.Name);
            }
   }


}

Okay, from the mesage, it is clear that the adaper is returning null, could it ne am issue with windows or code may worok on a different system?

Why should it work on your system? I've worked with Bluetooth for decades now (apps for our company) and when it came to PCs, over and over I'd get a support ticket then find the problematic PC didn't have Bluetooth or it was disabled.
In your case there is so much to investigate that I am not able to supply a fix or do this. Get to that addon site and lodge a ticket to see what they offer.
-> It's not funny when I ask "What other apps are you running that use Bluetooth?" This question is just one of many where I am exploring the usual source of the failure. In your case you are the developer so you know to dig deeper.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.