【问题标题】:Azure Storage File share dll causing runtime.compiler.unsafe error at runtime when working with Azure Function V1使用 Azure Function V1 时,Azure 存储文件共享 dll 在运行时导致 runtime.compiler.unsafe 错误
【发布时间】:2023-03-11 06:16:01
【问题描述】:
Azure.Storage.Files.Shares v12.0.0 - 12.5.0 出现运行时错误
Microsoft.Azure.WebJobs.Host.FunctionInvocationException:执行函数时出现异常:Function2 ---> System.IO.FileNotFoundException:无法加载文件或程序集“System.Runtime.CompilerServices.Unsafe,版本=4.0.4.1,
当我们通过 Nuget 在 Azure Function V1 中包含此内容时。
有什么办法可以使用这个吗?
我正在使用
ShareFileClient file = directory.GetFileClient(filename);
ShareFileDownloadInfo download = file.Download();
在 Download() 上它给出了这个错误。
【问题讨论】:
标签:
c#
azure-functions
azure-storage
azure-storage-files
.net-4.7.2
【解决方案1】:
Azure函数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);
}
}
}