1

I'm working on UWP Application to manage a BLE / GATT device. I'm following the official documentation from Microsoft (https://learn.microsoft.com/fr-fr/windows/uwp/devices-sensors/gatt-client). But I have a problem with the async function from BluetoothLEDevice class.

When I write the following line :

BluetoothLEDevice bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(deviceInfo.Id);

I have the followings errors :

  • Error CS0012 The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

  • Error CS0012 The type 'IAsyncActionWithProgress<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

  • Error CS0012 The type 'IAsyncOperation<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

  • Error CS0012 The type 'IAsyncOperationWithProgress<,>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.

Because sometimes, it is more readable

I tried to add manually the following reference (Like I found in multiple post) :

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\system.runtime.windowsruntime.dll

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

But, in the first case, VS saying it is already including by the generator system (or someting like this). And in the 2nd case, I have many class in my code that are referenced twice (Like Page for example)

What is the solution ?

xNiux
  • 145
  • 1
  • 9
  • A [screenshot of an error](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) in french is not helpful for most readers. It would help if you translated the exception message and added it as text – JonasH Apr 08 '20 at 14:48
  • For sure ! Mistake is corrected ! But I keep the screenshot (in english now), because, sometimes, it is more readable than the message list .... – xNiux Apr 09 '20 at 08:02

1 Answers1

1

My guess is that you lack references to the UWP api that is needed to use it in .Net applications.

Make sure you are using Package References in your project and you have added Microsoft.Windows.SDK.Contracts as a nuget package

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • Yes ! That 's was the problem !!! Microsoft.Windows.SDK.Contracts is missing ! thanks a lot ! – xNiux Apr 09 '20 at 12:36
  • But now, I have an error only at compilation : Error CS1704 An assembly with the same simple name 'Windows.Services.Store.StoreContract' has already been imported. Try removing one of the references (e.g. '%user%\.nuget\packages\microsoft.windows.sdk.contracts\10.0.18362.2005\ref\netstandard2.0\Windows.Services.Store.StoreContract.winmd') or sign them to enable side-by-side. – xNiux Apr 09 '20 at 13:37
  • This is probably because you ttried to add the references manually in your earlier attempts. Try remove any references other than the nuget package. – JonasH Apr 09 '20 at 14:46
  • Ok, thanks for your answer, but it is easier than this ! Nuget package is SDK 10.0.18362 and my app was designed for a 10.0.16299 target ! I just change target to 18362, and now it's ok ! – xNiux Apr 21 '20 at 07:35