Kid*_*Liu 4 c# desktop-application async-await windows-runtime win-universal-app
我正在桌面应用程序中编写代码,该应用程序使用适用于Windows 10的Wi-Fi Direct发现并连接到设备.我已按照说明操作如何从非WinRT环境调用Windows Runtime API,VS 2013上的一切都很好,除了以下几行,我将它们移动到面向.NET Framework 4.5的控制台应用程序中:
using System;
using Windows.Devices.Enumeration;
using Windows.Devices.WiFiDirect;
static void Main()
{
DoSomethingAsync().Wait();
}
static async void DoSomethingAsync()
{
var selector = WiFiDirectDevice.GetDeviceSelector(WiFiDirectDeviceSelectorType.DeviceInterface);
foreach (var info in await DeviceInformation.FindAllAsync(selector)) // <-- error
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
错误仍然存在
'await'要求类型'
Windows.Foundation.IAsyncOperation<Windows.Devices.Enumeration.DeviceInformationCollection>'具有合适的GetAwaiter方法.你错过了'系统'的使用指令吗?
以下库参考:image
我确信selector可以正确检索(类似于
System.Devices.InterfaceClassGuid:="{439B20AF-8955-405B-99F0-A62AF0C68D43}"
AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True
Run Code Online (Sandbox Code Playgroud)
),然后我认为黑客对Windows 10上的桌面应用程序仍然有效.
我该如何解决这个错误?
非常感谢@Yuval Itzchakov,@ vidalsasoon
事实证明我被System.Runtime.WindowsRuntime.dll找到的路径误导了.在C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5库中实际上是.NET Framework 4.0,其中没有定义这样的扩展方法(GetWaiter,AsTask...).但是,当您在VS中引用.NET Framework程序集时,看起来该文件夹是默认位置.
然后我引用了
System.Runtime.WindowsRuntime.dll的 C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dllWindows的 C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd现在它正在发挥作用.
| 归档时间: |
|
| 查看次数: |
3170 次 |
| 最近记录: |