我的电脑有一个可用的智能卡读卡器,应由下面的代码段返回:
string selector = Windows.Devices.SmartCards.SmartCardReader.GetDeviceSelector();
Windows.Devices.Enumeration.DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(selector);
但是,我收到此错误:
复制代码段错误CS4036'
IAsyncOperation<DeviceInformationCollection>
&#39;不包含&#39;GetAwaiter
&#39;的定义没有扩展方法&#39;GetAwaiter
&#39;接受类型&#39;IAsyncOperation<DeviceInformationCollection>
&#39;的第一个参数。可以找到(你是否错过了&#39;System
&#39;的使用指令?)
我该怎么做才能解决这个错误?
答案 0 :(得分:3)
错误消息为您提供了一个关于错误的非常好的提示。将using System;
指令添加到文件顶部。
为了将来参考,您可以通过在MSDN中搜索有问题的扩展方法来自行跟踪此问题,例如:搜索&#34; IAsyncOperation GetAwaiter扩展方法&#34;。当我这样做时,第一页是WindowsRuntimeSystemExtensions.GetAwaiter Method (IAsyncOperation),在该页面上,您可以看到该方法位于System
命名空间中,并在System.Runtime.WindowsRuntime.dll
程序集中定义。有了这两条信息,您可以仔细检查以确保.cs文件中包含using System;
,并且项目中有System.Runtime.WindowsRuntime.dll
程序集引用。