使用 Azure Function V1 时,Azure 存储文件共享 dll 在运行时导致 runtime.compiler.unsafe 错误

Azure Storage File share dll causing runtime.compiler.unsafe error at runtime when working with Azure Function V1

Azure.Storage.Files.Shares v12.0.0 - 12.5.0 出现运行时错误

Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Function2 ---> System.IO.FileNotFoundException : Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1,

当我们通过 Nuget 将其包含在 Azure Function V1 中时。

使用这个有什么解决方法吗?

我正在使用

 ShareFileClient file = directory.GetFileClient(filename);
 ShareFileDownloadInfo download = file.Download();

在下载()时出现此错误。

Azure function v1好像和最新版本的包有冲突,请使用Microsoft.WindowsAzure.Storage.File.

您可以参考这段代码下载您的文件:

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(<storage-connect-string>);
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
            CloudFileShare share = fileClient.GetShareReference(<share-name>);
            if (share.Exists())
            {
                // Get a reference to the root directory for the share.
                CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                // Get a reference to the directory we created previously.
                CloudFileDirectory sampleDir = rootDir.GetDirectoryReference(<directory-name>);

                // Ensure that the directory exists.
                if (sampleDir.Exists())
                {
                    // Get a reference to the file we created previously.
                    CloudFile file = sampleDir.GetFileReference("test.txt");

                    // Ensure that the file exists.
                    if (file.Exists())
                    {
                        log.Info(file.DownloadTextAsync().Result);
                    }
                }
            }