murkr
murkr

Reputation: 694

c#: BluetoothLe in WPF: some classes/methods not found

I'm writing a WPF Application (not an UWP) and I need to get BluetoothLE running.

I added the Bluetooth-usings:

using Windows.Devices.Bluetooth;
using Windows.Devices.Bluetooth.GenericAttributeProfile;

and I added the references to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll and to C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD.

But now two errors occure:

 var gattServicesResult = await device.GetGattServicesForUuidAsync(new Guid(RX_SERVICE_UUID));

gives the error 'BluetoothLedevice' does not contain a definition for 'GetGattServicesForUuidAsync' [...] (are you missing a using directive or an assembly reference?)

and

GattWriteResult result =
                await characteristic.WriteClientCharacteristicConfigurationDescriptorWithResultAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);

gives the error The type or namespace name 'GattWriteResult' could not be found (are you missing a using directive or an assembly reference?)

I also tried UwpDesktop.

Any idea whats goind on? Any help appreciated!

Upvotes: 1

Views: 1435

Answers (2)

Hongjia
Hongjia

Reputation: 73

Accroding to the most popular method, you should add references

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd

and

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll

to your project. But if you do this way, you will find some of the methods missing. So instead of adding

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd

we can add references

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD

C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd

and

C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.UniversalApiContract\6.0.0.0\Windows.Foundation.UniversalApiContract.winmd

to your project. This way works, I've been using it in my WPF project and everything works fine.

Upvotes: 4

nikname
nikname

Reputation: 21

Try to add a reference to a specific version, for example

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd

I don't know if this is the right way to solve this problem but it should works.

Upvotes: -1

Related Questions