ContentDialog showAsync() giving error: no definition for getAwaiter [duplicate] - c#

This question already has an answer here:
UWP app: FileOpenPicker PickSingleFileAsync() can't await
(1 answer)
Closed 5 years ago.
I am building an UWP app (C#) and on click of button, I want to verify input.
If verification fails, I want to display a message saying that there is wrong input.
this is my function which 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 (await msg.showAsync() ) is typed it stays underlined in red (in VS). The builder reads the following error:
Error CS4036 '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'?) testniStudioApp d:...\SecondPage.xaml.cs 43 Active
Now i tried to assign this call to variable (as I saw that someone solved similiar problem that way), but it still didn't worked.
Then I tried clearing NuGet cache and rebuilding project as stated here, but none of those solutions worked.
I have a hard time understanding what it wants from me.
Every single tutorial on how to display message was written in more or less the same manner, so I can't understand what can be wrong.

using System; was mising.
Thanks to comments for answer

Related

'The system cannot find the file specified' when clicking link [duplicate]

This question already has answers here:
When do we need to set ProcessStartInfo.UseShellExecute to True?
(5 answers)
Closed 2 months ago.
I am following this answer about making hyperlink work in a RichTextBox? by adding this:
private void mRichTextBox_LinkClicked (object sender, LinkClickedEventArgs e) {
System.Diagnostics.Process.Start(e.LinkText);
}
(Actually what I'm really doing is to go to the property of the control, click on the LinkClicked action, and just put the Start() method in there.)
However when clicking the link I get this error:
System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'https://example.com' with working directory 'XYZ'. The system cannot find the file specified.'
Why is that?
If you are using .NET 6 or higher, try this:
Process.Start( new ProcessStartInfo { FileName = e.LinkText , UseShellExecute = true } );

Stop "ding" when pressing Enter? (e.SuppressKeyPress is not recognized)

I've already read through this thread: Stop the 'Ding' when pressing Enter
I'm having no luck with e.SuppressKeyPress. I get an error "'KeyPressEventArgs' does not contain a definition for 'SuppressKeyPress' ..."
I am VERY VERY VERY VERY new to this. I cannot understate this enough. Please explain like I'm 5 years old. Sorry..
I'm using Visual Studio Express 2015 to create a Windows Form with C#.net.
Here is my code:
private void answer_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)ConsoleKey.Enter)
{
CheckAnswer();
}
}
I tried putting e.SuppressKeyPress = true; after my CheckAnswer(); function but I get red squigglies indicating it doesn't know what that is.
Why?
I've had no formal training in using C#.net and I'm missing the foundation of how this is all supposed to work which is messing me up I think. :(

Upload and display image in MVC application

So I followed this link http://www.c-sharpcorner.com/UploadFile/b696c4/how-to-upload-and-display-image-in-mvc/ given by #Div and it just gave me errors at ContentRepository service = new ContentRepository();. How am I suppose to replace that with something else that contain UploadImageInDataBase like int i = service.UploadImageInDataBase(file, model); ?
Private readonly DBContext db = new DBContext();
Gives me error "is inaccessible due to its protection level." And it wont be usable since it gives error "Cannot resolve", but I replaced it with private TestEntities db = new TestEntities(); and it works then. Hopefully it will cover everything?
I cant add anything inside var Content = new Content { as I getting "Cant resolve symbol X" inside it.
Then at
List<ImageVm> contentModel = content.Select(item => new ImageVm()) {
I'm getting following error:
Cannot implicitly convert type 'System.Linq.IQueryable'
to 'System.Collections.Generic.List'. An explicit
conversion exists (are you missing a cast?)
I followed every step carefully and I can't get any further.
The author basically just said "add this code" without explanation and I've no idea how to solve it.
Any idea how to solve it or have any better guides?

MessageBox & Dialogs on XNA (C#)

I'm having the following code as part of my XNA game:
private void gameOver()
{
if (!m_IsGameOver)
{
string message = String.Format("GAME OVER!!!{0}Your score is: {1}",
Environment.NewLine, GameScore);
if (MessageBox.Show(message, "GameOver", MessageBoxButtons.OK) == DialogResult.OK)
{
this.Exit();
}
m_IsGameOver = true;
}
}
private void gameWon()
{
string message = String.Format("You Won!!!{0}Your score is: {1}",
Environment.NewLine, GameScore);
if (MessageBox.Show(message, "You Won!", MessageBoxButtons.OK) == DialogResult.OK)
{
this.Exit();
}
}
For some reason,I received the following errors:
"The name 'MessageBox' does not exist in the current context"
"The name 'MessageBoxButtons' does not exist in the current context"
"The name 'DialogResult' does not exist in the current context"
I'm tring to add "System.Windows..." but it seems like that "System" does not have "windows" in it...
How can I solve this?
It seems that you are trying to use WinForms classes in XNA. However, according to the docs, WinForms is not included in XNA: As can be seen in the MessageBox docs, none of the MessageBox methods has the XNA logo in the first column, which means that none of them is supported in XNA. (See, for contrast, the docs on System.Linq.Enumerable, where all methods have the X-shaped XNA logo next to them).
For in-game GUIs, various solutions such as this one exist; more links are included in this, this and this SO question and this MSDN forum posting contains another list of links.
OK, I found the solution...
Very simple :/
Adding the "System.Windows" to the "References" section in the project :)
Also, if you try to bring in System.Windows.Forms, and you are using XNA's keys, like Keys.Up, there will be a name conflict with System.Windows.Forms Keys.

LiveSDK ( LiveConnect Api ) or SkyDrive Api for Windows Phone

I am not sure which assembly is the correct one to use for Windows Phone. The below Url shows an example of using LiveSDK.
http://nikovrdoljak.wordpress.com/2011/09/15/backup-your-windows-phone-isolated-storage-data-to-skydrive-using-live-connect-api/
I have added Microsoft.Live and Microsoft.Live.Control for the References
Code:
client.Session.Status != LiveConnectSessionStatus.Connected
Error:
'Microsoft.Live.LiveConnectSession' does not contain a definition for 'Status'
and no extension method 'Status' accepting a first argument of type 'Microsoft.Live.LiveConnectSession'
could be found (are you missing a using directive or an assembly reference?)
Code:
private LiveConnectClient client;
private void UploadPhoto_Click(object sender, EventArgs e)
{
if (client == null || client.Session == null || client.Session.Status != LiveConnectSessionStatus.Connected)
{
MessageBox.Show("You must sign in first.");
}
else
{
client.GetCompleted += new EventHandler<LiveOperationCompletedEventArgs>(GetFolderProperties_Completed);
// If you put photo to folder it becomes album.
client.GetAsync("me/skydrive/files?filter=folders,albums");
}
}
So it's fairly obvious the LiveConnectSession doesn't have the Status property. Why do you keep thinking it has it then?
In the example code he's using the Status property of the LiveConnectSessionChangedEventArgs class, not the LiveConnectSession.
A recommendation for re-reading the basics seems in order here.
Live SDk contain the SignIn Button and LiveConnet DLL. To connect to SKyDrive, it is required to use SignIn Button to sign in. Once it is connected, you can use the return session to create a LiveConnectClient.It is good practise to check if the session is still alive before doing any tasks on the SkyDrive.

Categories

Resources