Exception thrown: 'System.NotImplementedException' in Plugin.BLE.dll Exception thrown: 'System.NotImplementedException' in Plugin.BLE.dll An exception of type 'System.NotImplementedException' occurred in Plugin.BLE.dll but was not handled in user code

Sk 66 Reputation points
2025-05-23T15:10:59.49+00:00

I am migrating my project from Xamarin forms to Maui.In my project we have Bluetooth functionality implemented using Plugin.BLE. We didn't used Plugin.BLE nuget package instead we used plugin.Ble source code like projects . We are adding those projects as reference to our xamarin project ,The same I have done for MAUI. But in MAUI I am getting the below error

Exception thrown: 'System.NotImplementedException' in Plugin.BLE.dll Exception thrown: 'System.NotImplementedException' in Plugin.BLE.dll An exception of type 'System.NotImplementedException' occurred in Plugin.BLE.dll but was not handled in user code 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.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Michael Le (WICLOUD CORPORATION) 1,145 Reputation points Microsoft External Staff
    2025-07-28T08:36:28.0033333+00:00

    Hello,

    There are a few possible reasons why this happens:

    1. You're referencing the portable/shared version of Plugin.BLE.
    2. The platform-specific implementations (Android, iOS, etc.) are not being loaded properly.
    3. .NET MAUI uses updated dependency injection and platform-specific loading mechanisms compared to Xamarin.Forms.

    Recommended Solution

    For the smoothest migration experience, switch to the official Plugin.BLE NuGet package. The NuGet package handles all platform-specific loading automatically.

    <PackageReference Include="Plugin.BLE" Version="3.1.0" />
    

    There is also a beta version:

    <PackageReference Include="Plugin.BLE" Version="3.2.0-beta.1" />
    

    Alternative: Using Source Code Directly

    If you must use the source code version, follow these updated steps for .NET 9:

    1. Project References: Ensure you reference the platform-specific Plugin.BLE projects in your MAUI platform folders (Platforms/Android, Platforms/iOS, etc.).
    2. Update Target Frameworks: Your Plugin.BLE projects should target:
      • net9.0-android for Android
      • net9.0-ios for iOS
      • net9.0 for shared code
    3. Dependency Injection in MauiProgram.cs:
         public static class MauiProgram
         {
             public static MauiApp CreateMauiApp()
             {
                 var builder = MauiApp.CreateBuilder();
                 builder
                     .UseMauiApp<App>()
                     .ConfigureFonts(fonts =>
                     {
                         fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                     });
       
                 // Register BLE services
                 builder.Services.AddSingleton<Plugin.BLE.Abstractions.Contracts.IBluetoothLE>(
                     sp => Plugin.BLE.CrossBluetoothLE.Current);
       
                 return builder.Build();
             }
         }
      
    4. Platform-Specific Permissions:
      • Android (Platforms/Android/AndroidManifest.xml):
             <uses-permission android:name="android.permission.BLUETOOTH" />
             <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
             <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
             <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
             <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        
      • iOS (Platforms/iOS/Info.plist):
             <key>NSBluetoothAlwaysUsageDescription</key>
             <string>This app uses Bluetooth to connect to BLE devices.</string>
             <key>NSBluetoothPeripheralUsageDescription</key>
             <string>This app uses Bluetooth to connect to BLE devices.</string>
        
    5. Runtime Permissions: For Android 12+ (API 31+), ensure you handle runtime permission requests in your application code.
    6. Conditional Compilation: Use conditional compilation to include platform-specific logic where necessary:
         #if ANDROID
           // Android-specific BLE initialization
         #elif IOS
           // iOS-specific BLE initialization
         #endif
      
    7. Assembly Loading: Ensure the platform-specific assemblies are included in your build output.

    I hope this helps you resolve the issue.

    References:


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.