简体   繁体   English

使用 C# 的 Azure Blob 存储“找不到方法”

[英]Azure Blob Storage "Method not found" with C#

I have the folowing error when I apply the method GetBlockBlobReference() on a azure storage container.在 Azure 存储容器上应用GetBlockBlobReference()方法时出现以下错误。 I can fetch this container using the Microsoft.WindowsAzure.Storage NuGet, I can also see al the methods when I navigate into this Nuget, but at the compilation some methods are not found.我可以使用Microsoft.WindowsAzure.Storage NuGet 获取这个容器,当我导航到这个 Nuget 时,我也可以看到所有方法,但是在编译时找不到一些方法。

System.Private.CoreLib: Exception while executing function: AffluenceFunction. System.Private.CoreLib:执行功能时出现异常:AffluenceFunction。 GoogleAnalytics: Method not found: 'Void Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream(System.IO.Stream, Microsoft.WindowsAzure.Storage.AccessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions, Microsoft.WindowsAzure.Storage.OperationContext)' GoogleAnalytics:找不到方法:'Void Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.UploadFromStream(System.IO.Stream, Microsoft.WindowsAzure.Storage.AccessCondition, Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions, Microsoft.WindowsAzure.Storage.操作上下文)'

On the internet everybody says "downgrade" the Azure Storage Nuget version but is not working.在互联网上,每个人都说“降级”Azure Storage Nuget 版本,但没有用。 I have try with version 5, 6, 7 and even 9. Im using .NET Framework 4.7 as a class library who is called by a Function Project on version 2.我尝试过版本 5、6、7 甚至 9。我使用 .NET Framework 4.7 作为类库,它被版本 2 上的函数项目调用。

Some code (again the I can retreive the container):一些代码(我可以再次检索容器):

    public void UploadFile( CloudBlobContainer container )
    {
        var filePathOnServer = Path.Combine("C:/temp/test/c.csv");

        using (var fileStream = File.OpenRead(filePathOnServer))
        {
            var filename = "c.csv"; // Trim fully pathed filename to just the filename
            var blockBlob = container.GetBlockBlobReference(filename);

            blockBlob.UploadFromStream(fileStream);
        }
    }

We use Azure Blob Storage excly the same way on other project (others version of .NET) and it work fine!我们在其他项目(.NET 的其他版本)上以完全相同的方式使用 Azure Blob 存储,并且工作正常!

Thank you谢谢

Please install the latest blob storage nuget package: Microsoft.Azure.Storage.Blob, Version 10.0.3.请安装最新的 blob 存储 nuget 包: Microsoft.Azure.Storage.Blob,版本 10.0.3。

Install it both on the class library and the azure function.将它安装在类库和 azure 函数上。

I have a test with .net 4.7 class library and azure function v2, it works.我对 .net 4.7 类库和 azure 函数 v2 进行了测试,它可以工作。

The reason is that, WindowsAzure.Storage NuGet version 9.3 or below for .net core does only supports async method, so for function v2(which is .net core) does not have a definition UploadFromStream() .原因是, WindowsAzure.Storage NuGet 9.3 或以下版本仅支持 async 方法,因此函数 v2(即 .net core)没有定义UploadFromStream() But in Microsoft.Azure.Storage.Blob, Version 10.0.3 , it does support async and non-async method for .net core project.但是在Microsoft.Azure.Storage.Blob, Version 10.0.3 ,它确实支持 .net 核心项目的异步和非异步方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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