6

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?

  • 1
    You're missing some reference or `using` directive. – Paulo Morgado Aug 27 '15 at 06:21
  • For future reference: when you get an error like that, the first place to go is [the documentation](https://msdn.microsoft.com/en-us/library/hh582011(v=vs.110).aspx). That page is the **very first** search result when I enter "iasyncoperation getawaiter" in the MSDN search page. And looking at that documentation page, you can see clearly what assembly the method is defined in (which you need to reference) and that it's an extension method (meaning you have to have the proper `using` directive). – Peter Duniho Jan 18 '18 at 19:07

1 Answers1

14

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...

SelAromDotNet
  • 4,715
  • 5
  • 37
  • 59