ContentDialog showAsync () gives error: no definition for getAwaiter

I am creating a UWP (C #) app and on a button click, I want to validate the input. If the validation fails, I want to display a message about invalid input. this is my function that should handle this:

private async void AddContact_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
    DBHelper db = new DBHelper();
    if(i_name.Text != "" && i_phone.Text != "") {
        db.insertPerson(new Person(i_name.Text, i_phone.Text));
        Frame.Navigate(typeof(MainPage));
    } else {
        ContentDialog msg = new ContentDialog() {
            Title = "Empty input!",
            Content = "Please fill both fields!",
            CloseButtonText = "OK"
        };
        await msg.ShowAsync();
    }
}

      

However, when the last part is typed (waiting for msg.showAsync ()), it remains underlined in red (in VS). The builder reads the following error:

Error CS4036 "IAsyncOperation" does not contain a definition for "GetAwaiter" and the GetAwaiter extension method cannot be found that takes a first argument of type "IAsyncOperation" (are you missing a using directive for "System" ,?) testniStudioApp d: ... \ SecondPage. xaml.cs 43 Active

Now I tried to assign this call to a variable (as I saw someone solve a similar problem this way) but it still didn't work. Then I tried clearing the NuGet cache and rebuilding the project as mentioned here , but none of those solutions worked.

It's hard for me to understand what he wants from me. Every tutorial on how to display a message has been written in more or less the same way, so I can't figure out what might be wrong.

+3


source to share


1 answer


using System;

... Thanks to the comments for the answer



+7


source







All Articles