【问题标题】:Error while using Windows.Storage namespace使用 Windows.Storage 命名空间时出错
【发布时间】:2015-01-15 14:02:37
【问题描述】:

我正在尝试将字符串保存到我的临时文件夹中的文本文件中,但出现此错误:

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

谢谢

附:这是 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
        }
    }

}

【问题讨论】:

    标签: c# oop load save


    【解决方案1】:

    那是因为您缺少 .dll

    添加对此程序集的引用:
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5.1\System.Runtime.WindowsRuntime.dll

    这是桌面应用程序使用 WinRT API 的扩展方法“GetAwaiter”所必需的。

    【讨论】:

      猜你喜欢
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-25
      • 1970-01-01
      相关资源
      最近更新 更多