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

.NET7 Azure Functions加载Microsoft.Extensions.Caching.Memory失败求助

解决Azure Functions .NET7启动时无法加载Microsoft.Extensions.Caching.Memory程序集的问题

针对编译正常但启动时提示无法加载Microsoft.Extensions.Caching.Memory, Version=7.0.0.0的问题,以下是几个可尝试的解决方向:

1. 升级Microsoft.NET.Sdk.Functions到兼容.NET7的版本

你当前使用的Microsoft.NET.Sdk.Functions版本4.2.0发布时间较早,可能存在与.NET7依赖组件的兼容性冲突。建议升级到4.2.1及以上的稳定版本,修改项目文件中的引用:

<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.1" />

2. 添加程序集绑定重定向配置

部分间接依赖可能引用了旧版本的Microsoft.Extensions.Caching.Memory,导致版本冲突。可以通过以下方式强制统一版本:

  • 在项目的.csproj文件中开启自动绑定重定向:
<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
  • 或者手动在项目根目录创建app.config文件,添加明确的绑定规则:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Extensions.Caching.Memory" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

3. 排查并更新冲突的间接依赖

检查项目中其他包是否存在版本不兼容的情况:

  • FluentValidation.AspNetCore 10.3.0发布于.NET6时期,可能依赖旧版本的Microsoft.Extensions组件。建议升级到兼容.NET7的版本(如11.6.0或更高):
<PackageReference Include="FluentValidation.AspNetCore" Version="11.6.0" />
  • 使用NuGet包管理器的「查看依赖项」功能,逐一排查其他包是否间接引用了Microsoft.Extensions.Caching.Memory的旧版本,针对性升级冲突包。

4. 彻底清理本地构建残留

手动删除项目目录下的bin和obj文件夹,重启Visual Studio后,依次执行清理解决方案→生成解决方案的操作,避免旧编译文件干扰。

5. 验证本地.NET7环境

确保本地已安装**.NET7 SDK最新稳定版**,且Visual Studio 2022已更新到17.4及以上版本(该版本开始全面支持.NET7 Azure Functions)。

内容的提问来源于stack exchange,提问作者swaglord mcmuffin'

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 14:47:32