简体   繁体   中英

Azure function, Microsoft.WindowsAzure.Storage missing

I had a working http triggered Azure function a year ago. Not anymore. I created new azure function (runtime ~4) and now I can not compile it in Azure editor. It says "[Error] run.csx(2,1): error CS0006: Metadata file 'Microsoft.WindowsAzure.Storage' could not be found". It is simply geting list of files from my Azure BLOB storage. I am loosing my mind, I don't know what to cofigure, or how to change my code. Is Microsoft.WindowsAzure.Storage no loner supported? I was wondering about lowering my runtime version, but it is grey-out (I can not change it). I read this How to replace Microsoft.WindowsAzure.Storage with Microsoft.Azure.Storage.Blob But I trying #r "Azure.Storage.Blobs" have the same result

#r "Newtonsoft.Json"
#r "Microsoft.WindowsAzure.Storage"

using System;
using System.Configuration;
using System.Net;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
    log.LogInformation("C# HTTP trigger function processed a request.");

    string name = req.Query["name"];
    string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    dynamic data = JsonConvert.DeserializeObject(requestBody);
    name = name ?? data?.name;

string connectionString = "MY_CONNECTION_STRING";
var storageAccount = CloudStorageAccount.Parse(connectionString);

CloudBlobClient client = storageAccount.CreateCloudBlobClient();
string rootDirectoryName = name.Replace(" ", "");
CloudBlobContainer container = client.GetContainerReference("storage");
CloudBlobDirectory folder = container.GetDirectoryReference(rootDirectoryName);
CloudBlobDirectory modelFolder = folder.GetDirectoryReference("giftpics");

BlobResultSegment segment = await modelFolder.ListBlobsSegmentedAsync(null);
                    List<IListBlobItem> list = new List<IListBlobItem>();
                    list.AddRange(segment.Results);
                    while (segment.ContinuationToken != null)
                    {
                        segment = await container.ListBlobsSegmentedAsync(segment.ContinuationToken);
                        list.AddRange(segment.Results);
                    }
List<string> blobNames = list.OfType<CloudBlockBlob>().Select(b => b.Name.Replace(rootDirectoryName, "").Replace("giftpics", "").Replace("/", "")).ToList();

  string contents = JsonConvert.SerializeObject(blobNames);
     return new OkObjectResult(contents);
}

I tried to re produce the scenario in my system able to get the all blobs names,I created the azure function app tried with code,

在此处输入图像描述

在此处输入图像描述

OUTPUT

Files in Azure Storage

在此处输入图像描述

在此处输入图像描述

thanks for your answer but I created new Azure Function APP with .net 3.1 which solved my issue

I struggled on this too.....I think I might have found a solution for it, not sure. But try this, it might work:

  1. Upload an empty function.proj in the Azure Portal (ie while in the 'Code + Test' view while editing your Azure Function)
  2. Select the function.proj file (using the dropdown)
  3. Manually enter (or copy/paste) your code into the function.proj. You should have a screen that looks something like below at this point:

在此处输入图像描述

  1. Save. It should now be restoring packages and hopefully compile your code successfully.

Try changing your runtime to ~3. This worked for me, but I am not a developer so I have no idea what any ramifications this might have.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM