c# - 使用 Azure Function V1 时,Azure 存储文件共享 dll 在运行时导致 runtime.compiler.unsafe 错误
问题描述
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() 上它给出了这个错误。
解决方案
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);
}
}
}
推荐阅读
- php - 使用包含的基本帮助
- python - 如何根据 python 中的 datetime.today() 获取前 X 个月的开始和结束日期?
- c# - 有没有办法从另一个表单将表记录数据从 sql server 获取到 web 表单?
- scala - 如何在scala中拆分和连接字符串?
- sql - 如何将 SQL 中具有四分之一小时值的下一行扩展/填充为每小时值(MSSQL)
- spring-cloud-stream - Spring Cloud Stream 反应式 kafka 生产者 ack
- java - 如何使用 Java JDA 从 Discord Guild 中检索特定成员
- javascript - 从 formik 内部的组件设置 formik 值
- jquery - 单击 $this 复选框
- javascript - 如何在conduit.productionready.io(假api)中获取我的帖子