我有一个 Azure Function 应用程序,旨在删除 Azure 存储中的 blob 图像。该函数映射到存储帐户,并且在本地运行时完美运行,指向 Azure 存储帐户。
详情:
错误信息:
Exception while executing function: EliminarImagen Could not load file or assembly 'System.Memory.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
我尝试过部署模式设置,将功能设置为
目标运行时间设置为
但总是遇到同样的错误...
这是 .csproj 文件:
<PackageReference Include="Azure.Storage.Blobs" Version="12.22.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.5.0" />
<PackageReference Include="System.Memory.Data" Version="8.0.1" />
也许我错过了一些东西,但我已经没有想法了,执行删除 blob 的代码是这样的:
using Azure.Storage.Blobs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
namespace FuncionEliminarImagenes.Clases
{
public static class EliminarImagen
{
[FunctionName("EliminarImagen")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route =
"eliminaImagen/{containerName}/{imageName}")] HttpRequest req, string containerName,
string imageName, ILogger log)
{
log.LogInformation("Initializing the function, ready to receive requests...");
BlobServiceClient blobServiceClient = new BlobServiceClient(Conexion.connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
// Check if container exists
if (!await containerClient.ExistsAsync())
{
log.LogError($"The container {containerName} does not exist.");
return new NotFoundObjectResult($"The container {containerName} does not exist.");
}
BlobClient blobClient = containerClient.GetBlobClient(imageName);
log.LogInformation($"Attempting to delete the image: {imageName} in the container: {containerName}");
if (!await blobClient.ExistsAsync())
{
log.LogWarning($"The image {imageName} does not exist in the container {containerName}.");
return new NotFoundObjectResult($"The image {imageName} does not exist in the container {containerName}.");
}
else
{
var deleteResponse = await blobClient.DeleteIfExistsAsync();
if (deleteResponse)
{
log.LogInformation($"The image {imageName} was deleted from the container {containerName}.");
return new OkObjectResult($"The image {imageName} was successfully deleted.");
}
return new StatusCodeResult(200);
}
}
}
}
您需要更新您的函数才能使用 .net 8。我假设您正在使用隔离进程模型。我最近也遇到这个问题了
您需要更新应用程序以使用 Microsoft.Azure.Functions.Worker 包而不是 WebJobs 包。
这篇 MS 文章介绍了如何更新。
https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8