I am trying to save the string into a text file in my temp folder but i have this error:
Error2'await' requires that the type 'Windows.Foundation.IAsyncAction' have a
suitable GetAwaiter method. Are you missing a using directive for 'System'
Thanks
PS this is C# console app.
My Code:
using System;
using System.IO;
using System.Linq;
using Windows.Storage;
public static class Storage
{
public static async void SaveData()
{
string myString = "This is the data I want to save";
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
// Add: using Windows.Storage;
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder;
// Optionally overwrite any existing file with CreationCollisionOption
StorageFile file = await localFolder.CreateFileAsync("mySaveFile.txt", CreationCollisionOption.ReplaceExisting);
try
{
if (file != null)
{
await FileIO.WriteTextAsync(file, myString);
}
}
catch (FileNotFoundException)
{
// Error saving data
}
}
}
That's because you're missing a .dll
Add a reference to this assembly:
C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETCore\\v4.5.1\\System.Runtime.WindowsRuntime.dll
This is necessary for desktop app to use the extension method "GetAwaiter" from WinRT API.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.