本文介绍了'Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync()'不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有以下代码显示应用程序中的文件选择器: var FilePicker = new Windows.Storage.Pickers .FileOpenPicker(); FilePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail; FilePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder; FilePicker.FileTypeFilter.Add(。pcs); FilePicker.FileTypeFilter.Add(。pcp); Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync();然而, Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync(); 在编译期间导致此错误: 错误CS4036'IAsyncOperation< StorageFile>'不包含定义'GetAwaiter'和没有扩展方法'GetAwaiter'接受类型'IAsyncOperation< StorageFile''的第一个参数可以找到(你是否缺少一个using'System' / p> 为什么会发生这种情况?我得到了MSDN的代码。 解决方案 div> 您在使用中缺少对 System 的明显引用。 using System;为什么你需要这个引用以及为什么它抱怨它缺少一个看似未使用的方法? > 使用 await ,它实际上调用 WindowsRuntimeSystemExtensions.GetAwaiter 方法 IAsyncOperation (以获得 TaskAwaiter 到await)。由于 WindowsRuntimeSystemExtensions 驻留在 System 命名空间中,因此您需要使用以获取扩展方法。 I have the following code that shows a File Picker in an application:var FilePicker = new Windows.Storage.Pickers.FileOpenPicker();FilePicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;FilePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder;FilePicker.FileTypeFilter.Add(".pcs");FilePicker.FileTypeFilter.Add(".pcp");Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync();However, Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync() causes this error during compilation: Error CS4036 'IAsyncOperation<StorageFile>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<StorageFile>' could be found (are you missing a using directive for 'System'?)Why is this happening? I got the code from MSDN. Could someone please help me?Note: I am programming for Universal Windows. 解决方案 You are missing the obvious reference to System in your usings.using System;Why do you need this reference and why it complains it is missing a seemingly unused method?With await, it actually calls WindowsRuntimeSystemExtensions.GetAwaiter, an extension method over IAsyncOperation (to get the TaskAwaiter to await). Since WindowsRuntimeSystemExtensions resides in the System namespace, you need that using to get the extension method. 这篇关于'Windows.Storage.StorageFile File = await FilePicker.PickSingleFileAsync()'不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-30 22:53