c# - 文件不包含 "WriteAllTextAsync"的定义?

标签 c# .net azure azure-storage azure-blob-storage

我正在遵循 Microsoft 的快速入门指南,了解如何使用 Azure Blobs里面有一个特定的部分,您可以在其中创建要上传的示例文本文件。但是,我不确定出了什么问题,因为此代码段会产生一个错误,指出 File does not contains a definiton for "WriteAllTextAsync":

// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "quickstart" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);

// Write text to the file
await File.WriteAllTextAsync(localFilePath, "Hello, World!");

// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);

Console.WriteLine("Uploading to Blob storage as blob:\n\t {0}\n", blobClient.Uri);

// Open the file and upload its data
using FileStream uploadFileStream = File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();

有谁知道为什么会这样吗?我已经导入了所有正确的 NuGet 等,但我似乎无法弄清楚,因为这直接是他们的代码。

最佳答案

我建议检查您使用的框架/网络核心版本。 根据this ms doc

File.WriteAllTextAsync 方法 适用于:

.NET

5.0 预览版 7

.NET Core

3.1 3.0 2.2 2.1 2.0

.NET 标准

2.1

关于c# - 文件不包含 "WriteAllTextAsync"的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63235559/

相关文章:

c# - 获取 UI 线程上的锁

c# - 检查数组的所有值是否不同

c# - 为什么没有像 String.Empty 这样的 Char.Empty?

javascript - 为 DotNet.HighCharts 中的每一列设置不同的颜色

azure - 仅授权特定用户使用 azure webapp

python - 如何使用 Python API 修改 Azure Block Blob 中的特定 block ?

c# - 如果服务主体被授予其所属的组,我如何验证该角色是否具有应用程序角色?

c# - 无法在列表中将类型 'uint' 隐式转换为 'T'(来自类模板)

c# - Enum,委托(delegate)字典集合,其中委托(delegate)指向重载方法

c# - 如何检索 LoaderExceptions 属性?