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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With