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

macOS下VS Code调试Python版Azure Functions遇System.Memory.Data加载失败

解决VS Code调试Python Azure Functions时System.Memory.Data加载失败问题

问题核心现象

在macOS的VS Code中使用「Attach to Python functions」调试Python版Azure Functions时,启动阶段抛出以下错误:

[2025-03-31T09:40:13.208Z] A host error has occurred during startup operation 'fea6e68a-2e7f-43ca-b8e4-3e32814d60fa'.
[2025-03-31T09:40:13.208Z] System.Private.CoreLib: Exception has been thrown by the target of an invocation. 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.
[2025-03-31T09:40:13.208Z] .
Value cannot be null. (Parameter 'provider')
[2025-03-31T09:40:13.233Z] Host startup operation has been canceled

代码回滚、重装VS Code均无效,但Docker容器运行正常,且问题无征兆反复出现。

解决思路与步骤

1. 清理Azure Functions Core Tools缓存

本地Core Tools的缓存文件可能损坏,导致.NET依赖加载失败:

rm -rf ~/Library/Application\ Support/AzureFunctionsTools

执行后重启VS Code,重新尝试调试。

2. 重装Azure Functions Core Tools

Core Tools版本异常或文件损坏是常见诱因,卸载后重新安装稳定版:

# 卸载现有版本
brew uninstall azure-functions-core-tools
# 安装v4稳定版(适配多数Python函数场景)
brew install azure-functions-core-tools@4

3. 重置本地Python虚拟环境

虚拟环境的依赖残留可能与调试环境冲突,彻底重建:

# 删除现有虚拟环境
rm -rf venv
# 创建新虚拟环境
python3 -m venv venv
# 激活环境
source venv/bin/activate
# 重新安装依赖
pip install -r requirements.txt

4. 重置VS Code Azure Functions扩展

扩展缓存或状态异常可能导致调试流程出错:

  • 在VS Code中卸载「Azure Functions」扩展
  • 删除扩展缓存目录:
    rm -rf ~/.vscode/extensions/ms-azuretools.vscode-azurefunctions-*
    
  • 重启VS Code后重新安装该扩展

5. 强制指定.NET Runtime版本

调试时使用的.NET Runtime版本与依赖不匹配,在local.settings.json中明确指定:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_DOTNET_RUNTIME_VERSION": "6.0",
    // 保留原有其他配置项
  }
}

内容的提问来源于stack exchange,提问作者romtecmax

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 14:25:04