1

My computer has a working smartcard reader that should be returned by the code snippet below:

string selector = Windows.Devices.SmartCards.SmartCardReader.GetDeviceSelector();
Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);

However, I am getting this error:

Error CS4036 'IAsyncOperation<DeviceInformationCollection>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<DeviceInformationCollection>' could be found (are you missing a using directive for 'System'?)

The code snippet is copied from Microsoft's C# Sample Code

What can I do to solve this error?

svick
  • 236,525
  • 50
  • 385
  • 514
Believe2014
  • 3,894
  • 2
  • 26
  • 46

1 Answers1

4

The error message is giving you a pretty good hint about what is wrong. Add the using System; directive to the top of your file.

For future reference, you can track this down yourself by searching MSDN for the extension method in question, e.g. search for "IAsyncOperation GetAwaiter extension method". When I do that, the first page is WindowsRuntimeSystemExtensions.GetAwaiter Method (IAsyncOperation), and on that page you can see that the method is in the System namespace, and defined in the System.Runtime.WindowsRuntime.dll assembly. With those two pieces of information you can double-check to make sure you have using System; in your .cs file, and that you have the System.Runtime.WindowsRuntime.dll assembly reference in the project.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
John Koerner
  • 37,428
  • 8
  • 84
  • 134