1

Is there a way to use a C# library written in the UWP framework in a .NET Framework (or .NET Standard) application?

I try to get a Bluetooth (BLE) module working for a .NET Framework application in Windows 11. As far as I know, the native Bluetooth support is only possible using UWP, so I can't switch here. The .NET Framework application is also fixed, it contains external libraries from suppliers that can't be updated to .NET Standard or .NET 6. However, I can write an adapter class that uses .NET Standard 2.0, so I can work with it if a solution for .NET Standard exists.

When I try to reference a UWP class from .NET Framework or .NET Standard, I always get an error like this:

"Project BLE_Module is not compatible with netstandard2.0(.NETStandard,Version=v2.0). Project BLE_Module supports: uap.10.0.17763(UAP,Version=v10.0.17763)"

I know I can reference .NET Standard classes from UWP, but that does not help me, as the UWP module is just an execution module for Bluetooth requests and does not include any business logic.

What can I do to resolve the problem? I could write the BLE_Module as a stand-alone service and interact with the service from the main program during runtime, but before I embark on this journey, I would like to know if there are any possibilities to make it work without such a specific solution (that also reduces testability and increases bug chances).

2 Answers 2

3

Is there a way to use a C# library written in the UWP framework in a .NET Framework (or .NET Standard) application?

Short answer: No.

That's why .NET Standard was introduced in the first place, i.e. to be able to share common code between different .NET implementations.

A class library that targets a specific platform, such as UWP, cannot be consumed from an app that targets another platform, such as for example the .NET Framework.

Sign up to request clarification or add additional context in comments.

1 Comment

Clear-cut answer, thanks.
2

Native Bluetooth support does not require UWP. The Bluetooth libraries are written for the WinRT API, so you can use them from C++ or .NET Framework desktop applications.

See https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance for more info.

If you however have an additional layer written in UWP on top of the native Bluetooth libraries, then I'm not sure if that can be consumed in a normal .NET Framework application.

3 Comments

Thanks for your answer. But it says that specifically PairAsync(), which is crucial for my application, is not supported (see learn.microsoft.com/en-us/windows/apps/desktop/modernize/…), and the alternative TryRegisterForAllInboundPairingRequests() does only work with Windows 10 IoT Core apps (which does not help me). So I would not be able to pair with my BLE device.
You can use learn.microsoft.com/en-us/uwp/api/…. See github.com/microsoft/Windows-universal-samples/blob/main/… how to use it. I use that in a c++ win32 application and it works fine.
Oh, I see, the problem exists only for DeviceInformationPairing, not DeviceInformationCustomPairing. I should read more accurately. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.