2015-01-15 7 views
3

Я пытаюсь сохранить строку в текстовый файл в моей папке темп, но у меня есть эта ошибка:Ошибка при использовании Windows.Storage имен

Error2'await' requires that the type 'Windows.Foundation.IAsyncAction' have a 
suitable GetAwaiter method. Are you missing a using directive for 'System' 

Благодаря

P.S. это приложение консоли C#.

Мой код:

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

} 

ответ

1

Это потому, что вы не нашли .dll

Добавить ссылку на эту сборку:
C: \ Program Files (x86) \ Ссылка Сборки \ Microsoft \ Framework .NETCore \ v4.5.1 \ System.Runtime.WindowsRuntime.dll

Это необходимо для настольного приложения, чтобы использовать метод расширения "GetAwaiter" из WinRT API.

+0

_using Windows.Storage_ как я должен это получить ... –

Смежные вопросы