You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Function从.NET6升级到.NET8后出现System.Memory.Data程序集加载失败错误

Azure Function从.NET6升级到.NET8后出现System.Memory.Data程序集加载失败错误

问题背景

我想把我的Azure Function从.NET 6升级到.NET 8,先给大家看看升级前的csproj文件:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <UseNETCoreGenerator>true</UseNETCoreGenerator>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.7.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.4.4" />
    <PackageReference Include="Azure.Storage.Files.DataLake" Version="12.2.2" />
    <PackageReference Include="Microsoft.Azure.DataLake.Store" Version="1.1.21" />
    <PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.36" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.9.1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
    <PackageReference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication" Version="2.4.1" />
    <PackageReference Include="SharpZipLib" Version="1.2.0" />
    <PackageReference Include="SSH.NET" Version="2016.1.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

已完成的升级操作

我已经完成了项目文件的.NET 8升级,也执行了清理、还原、重新生成等步骤,升级后的csproj文件如下:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Classes\DataLakeGen1Helper.cs" />
  </ItemGroup>

  <ItemGroup>
    <!-- Azure Packages -->
    <PackageReference Include="Azure.Core" Version="1.44.1" />
    <PackageReference Include="Azure.Identity" Version="1.13.1" />
    <PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.7.0" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
    <PackageReference Include="Azure.Storage.Files.DataLake" Version="12.21.0" />
    <!-- Azure Functions & Durable Task -->
    <PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.41" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="3.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />
    <!-- Utility Libraries -->
    <PackageReference Include="SharpZipLib" Version="1.4.2" />
    <PackageReference Include="SSH.NET" Version="2024.2.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

升级过程中没有出现部署或构建错误,但运行Function的时候却弹出了下面的错误:

{"Message":"Something went wrong while processing your request","ExceptionMessage":"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.","ExceptionType":"System.IO.FileNotFoundException","StackTrace":" at Azure.RequestFailedException.AppendContentAndHeaders(Response response, StringBuilder messageBuilder)\r\n   at Azure.RequestFailedException.CreateExceptionDetails(Response response, RequestFailedDetailsParser parser)\r\n   at Azure.RequestFailedException..ctor(Response response, Exception innerException, RequestFailedDetailsParser detailsParser)\r\n   at Azure.Storage.Blobs.ContainerRestClient.CreateAsync(Nullable`1 timeout, IDictionary`2 metadata, Nullable`1 access, String defaultEncryptionScope, Nullable`1 preventEncryptionScopeOverride, CancellationToken cancellationToken)\r\n   at Azure.Storage.Blobs.BlobContainerClient.CreateInternal(PublicAccessType publicAccessType, IDictionary`2 metadata, BlobContainerEncryptionScopeOptions encryptionScopeOptions, Boolean async, CancellationToken cancellationToken, String operationName)\r\n  at Azure.Storage.Blobs.BlobContainerClient.CreateIfNotExistsInternal(PublicAccessType publicAccessType, IDictionary`2 metadata, BlobContainerEncryptionScopeOptions encryptionScopeOptions, Boolean async, CancellationToken cancellationToken)\r\n   at Azure.Storage.Blobs.BlobContainerClient.CreateIfNotExistsAsync(PublicAccessType publicAccessType, IDictionary`2 metadata, BlobContainerEncryptionScopeOptions encryptionScopeOptions, CancellationToken cancellationToken)\r\n   at DurableTask.AzureStorage.Storage.ClientResponseExtensions.DecorateFailure[T](Task`1 responseTask)\r\n   at DurableTask.AzureStorage.Storage.BlobContainer.CreateIfNotExistsAsync(CancellationToken cancellationToken) in ///src/DurableTask.AzureStorage/Storage/BlobContainer.cs:line 51\r\n   at DurableTask.AzureStorage.Partitioning.AppLeaseManager.CreateContainerIfNotExistsAsync() in ///src/DurableTask.AzureStorage/Partitioning/AppLeaseManager.cs:line 207\r\n   at DurableTask.AzureStorage.AzureStorageOrchestrationService.GetTaskHubCreatorTask() in ///src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs:line 371\r\n   at DurableTask.AzureStorage.AzureStorageOrchestrationService.EnsureTaskHubAsync() in ///src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs:line 352\r\n   at DurableTask.AzureStorage.AzureStorageOrchestrationService.GetOrchestrationStateAsync(String instanceId, Boolean allExecutions, Boolean fetchInput) in ///src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs:line 1827\r\n   at Microsoft.Azure.WebJobs.Extensions.DurableTask.AzureStorageDurabilityProvider.GetOrchestrationStateWithInputsAsync(String instanceId, Boolean showInput) in ///src/WebJobs.Extensions.DurableTask/AzureStorageDurabilityProvider.cs:line 81\r\n   at Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableClient.Microsoft.Azure.WebJobs.Extensions.DurableTask.IDurableOrchestrationClient.GetStatusAsync(String instanceId, Boolean showHistory, Boolean showHistoryOutput, Boolean showInput) in ///src/WebJobs.Extensions.DurableTask/ContextImplementations/DurableClient.cs:line 465\r\n   at Microsoft.Azure.WebJobs.Extensions.DurableTask.HttpApiHandler.HandleGetStatusRequestAsync(HttpRequestMessage request, String instanceId, Nullable`1 returnInternalServerErrorOnFailure, IDurableOrchestrationClient existingClient) in ///src/WebJobs.Extensions.DurableTask/HttpApiHandler.cs:line 635\r\n   at Microsoft.Azure.WebJobs.Extensions.DurableTask.HttpApiHandler.HandleRequestAsync(HttpRequestMessage request) in ///src/WebJobs.Extensions.DurableTask/HttpApiHandler.cs:line 376"}

尝试过的解决方法

我顺着这个错误方向查了很多内容,还尝试手动引用System.Memory.Data:

  • 直接添加了System.Memory.Data的包引用,确保它出现在bin\Debug\net8.0文件夹中
  • 反复执行dotnet clean、dotnet restore和dotnet build命令
  • 修改后的csproj文件如下:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>

  <!-- Generates runtimeconfig.json -->
  <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Classes\DataLakeGen1Helper.cs" />
  </ItemGroup>

  <ItemGroup>
    <!-- Azure Packages -->
    <PackageReference Include="Azure.Core" Version="1.44.1" />
    <PackageReference Include="Azure.Identity" Version="1.13.1" />
    <PackageReference Include="Azure.Security.KeyVault.Certificates" Version="4.7.0" />
    <PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
    <PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
    <PackageReference Include="Azure.Storage.Files.DataLake" Version="12.21.0" />

    <!-- Azure Functions & Durable Task -->
    <PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.5" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Core" Version="3.0.41" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="3.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />

    <!-- Utility Libraries -->
    <PackageReference Include="SharpZipLib" Version="1.4.2" />
    <PackageReference Include="SSH.NET" Version="2024.2.0" />
    <PackageReference Include="System.Memory.Data" Version="6.0.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <Content Update="wwwroot\web.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>

<ItemGroup>
  <Reference Include="System.Memory.Data">
    <HintPath>bin\Debug\net8.0\System.Memory.Data.dllSystem.Memory.Data.dll</HintPath>
    <Private>true</Private>
  </Reference>
</ItemGroup>

</Project>

但修改后还是出现完全一样的错误,我是.NET新手,实在不知道该怎么办了,希望大家能给我一些建议或方向,非常感谢!


备注:内容来源于stack exchange,提问作者OrganicMustard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 10:42:58