Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to let the user browse for a file with the FileOpenPicker class, but when I use the PickSingleFileAsync function with await, I get following error:

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

This is the function that gives the error on it's last line:

private async void browseFileButton_Click(object sender, RoutedEventArgs e) {
    FileOpenPicker filePicker = new FileOpenPicker();
    filePicker.ViewMode = PickerViewMode.Thumbnail;

    selectedFile = await filePicker.PickSingleFileAsync();
}

The documentation from Microsoft contains an example that uses the FileOpenPicker in the same way. Has anybody had this problem or has anybody a solution for this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
355 views
Welcome To Ask or Share your Answers For Others

1 Answer

do you have:

using System;

at the top of the class file? I just tried adding your sample to a project and duplicated your error when I removed this reference...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...