1

I want to call the below Line of code from BluetoothLE Sample:

static async Task<int> OpenDevice(DeviceInformation DeviceInfo)
{
// some code

await BluetoothLEDevice.FromIdAsync(DeviceInfo.Id).AsTask().TimeoutAfter(_timeout);

// some code
}

'FromIdAsync' function is from 'BluetoothLEDevice' Class:

[RemoteAsync]
public static IAsyncOperation<BluetoothLEDevice> FromIdAsync(string deviceId);

I am getting this Exception:

Method not found: 'System.Threading.Tasks.Task`1<System.__Canon> System.Threading.Tasks.Task.FromCancellation(System.Threading.CancellationToken)'.

I have searched a lot, and there is not enough information about 'FromCancellation' method. It seems this method automatically called when 'await' completes. (its my own supposition)

I am thinking of avoiding 'await' call. Any work around or help would be appreciated. I have 'DeviceInformation' Object which have Device ID. I want to get the 'BluetoothLEDevice' object to move further with 'Services' and 'Characteristics'. I am building a Windows console Application.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Usman
  • 43
  • 5
  • Why are you using `IAsyncOperation` for `FromIdAysnc` instead of `Task`. Removing `await` only means the exception will still be thrown but unknown to any calling contexts. – ethane Jul 03 '19 at 07:33
  • Check this out: https://stackoverflow.com/a/10045151/4716488 – ethane Jul 03 '19 at 07:37
  • IAsyncOperation is from .NetFramework, using Windows.Devices.Bluetooth; – Usman Jul 03 '19 at 07:37
  • my actual code of Line is: _selectedDevice = await BluetoothLEDevice.FromIdAsync(foundId).AsTask().TimeoutAfter(_timeout); – Usman Jul 03 '19 at 07:39
  • Have you updated .Net or Nuget packages recently? People seem to have had similar issues related to versioning. eg https://social.msdn.microsoft.com/Forums/en-US/475a9f29-9b5a-4ea1-b45b-460c2f941d76/why-my-uwp-project-always-reports-missingmethodexception-error?forum=wpdevelop – GazTheDestroyer Jul 03 '19 at 09:11

1 Answers1

0

As per mentioned by 'GazTheDestroyer', I checked all the Dependencies and Packages. There were redundant packages installed. There were many versions of .NET Framework in multiple folders like .Net_Framework, .NET_Portable, .NET_Core and some other packages.

In my Project's settings: I used the reference to assembly of System.Runtime.WindowsRuntime.dll from .NET_Framework. But my project's target was pointing towards .NET_Core which also have the same DLL.

So i updated from:

<TargetFramework>core2.2</TargetFramework>

to:

<TargetFramework>net48</TargetFramework>

That was the reason, due to which it was not working.

Usman
  • 43
  • 5