Issue
I am trying to add metadata to my Azure blobs (pictures) from my Xamarin app. I first tried this in a C# console app and it worked, but when I tried to put the code in my Xamarin app (as a new, seperate class) I got the following error.
CS8370 Feature 'async streams' is not available in C# 7.3. Please use language version 8.0 or greater.
The error points to the first await (await foreach (BlobItem ...). I am using netstandard 2.0 (in my .csproj file it says < TargetFramework>netstandard2.0</ TargetFramework>)
I was wondering if i could change my code / change any settings to make it work?
This is my code:
static async Task AddType()
{
string connectionString = "xxx";
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
// Get the container client object
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("raspberryuploads");
// List all blobs in the container
await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
{
BlobClient blobClient = new BlobClient("xxx", "yyy", blobItem.Name);
IDictionary<string, string> metadata = new Dictionary<string, string>();
// Add metadata to the dictionary by using key/value syntax
metadata["Type"] = "Result";
// Set the blob's metadata.
await blobClient.SetMetadataAsync(metadata);
}
}
This code is mainly made up from microsoft documentation.
Solution
The error message means that you try to use a C# feature which is not part of your currently used version. You are using C# 7.3 which comes with .NET Standard 2.0. But you need C# 8 which comes with .NET Standard 2.1. You can read more about it here https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version and here https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8. Try to upgrade your .NET Standard version to 2.1 and it should run.
Answered By - Sebastian S.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.