添加插件后无法在Rider本地运行Azure Functions项目
Azure Functions本地运行故障排查方案
问题概述
安装Azure Functions + Azure Service Bus相关插件后,无法通过Rider本地运行函数,已尝试以下操作但未解决:
- 删除bin和obj文件夹
- 卸载并重新安装Rider的Azure Toolkit插件
- 删除
~\.AzureToolsForIntelliJ和~\.azurefunctions目录 - 清除缓存重启Rider
- 升级所有NuGet包至最新版本
出现两类错误:
- Rider运行时程序集加载错误:
System.Private.CoreLib: Exception has been thrown by the target of an invocation. Microsoft.Azure.WebJobs.Extensions.Storage.Queues: 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.
Value cannot be null. (Parameter 'provider')
- 直接用
func.exe运行时提示需要Microsoft.NET.Sdk.Functions4.5.0及以上版本,但项目.csproj已引用4.6.0版本;当前func.exe版本为4.0.6610。
项目.csproj配置:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> <RootNamespace /> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)' == 'Release'"> <RuntimeIdentifier>win-x86</RuntimeIdentifier> <PublishReadyToRun>true</PublishReadyToRun> </PropertyGroup> <ItemGroup> <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.2" /> <PackageReference Include="Azure.Storage.Queues" Version="12.21.0" /> <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.46.0-preview.2" /> <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" /> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" /> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage.Queues" Version="5.3.3" /> <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.1.0-preview" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" /> <PackageReference Include="PlayFabAllSDK" Version="1.192.241108" /> <PackageReference Include="Sentry.AspNetCore" Version="4.13.0" /> <PackageReference Include="Sentry.Extensions.Logging" Version="4.13.0" /> <PackageReference Include="SharpZipLib" Version="1.4.2" /> <PackageReference Include="System.Memory" Version="4.6.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>
解决思路
1. 修复System.Memory.Data程序集缺失问题
- 显式添加NuGet包:在项目中直接添加
System.Memory.Data包,指定版本6.0.0(与错误提示版本匹配),执行命令:dotnet add package System.Memory.Data --version 6.0.0 - 排查依赖冲突:查看项目的传递依赖树,确认是否有其他包强制引入了旧版本的
System.Memory.Data,执行命令:
若发现冲突,可通过dotnet list package --include-transitivePackageReference的ExcludeAssets属性排除旧版本依赖。
2. 解决func.exe与Sdk版本不兼容问题
- 升级Azure Functions Core Tools:当前
func.exe版本4.0.6610为旧版本,与Microsoft.NET.Sdk.Functions4.6.0不匹配,升级到最新稳定版:- 使用npm安装:
npm install -g azure-functions-core-tools@4 --unsafe-perm true - 或从官方渠道下载安装包手动更新。
- 使用npm安装:
- 验证Rider工具路径:在Rider的Azure Functions运行配置中,确认
Azure Functions Core Tools的路径指向最新安装的版本,避免使用旧版本的func.exe。
3. 其他排查优化
- 清理全局NuGet缓存:清除本地缓存后重新还原依赖,避免缓存损坏导致的问题:
dotnet nuget locals all --clear dotnet restore - 检查local.settings.json配置:确认
AzureWebJobsStorage字段配置有效(本地可使用UseDevelopmentStorage=true),空值或无效配置会触发Value cannot be null. (Parameter 'provider')错误。 - 隔离第三方依赖:临时移除项目中的预览版包(如
Microsoft.Azure.Cosmos预览版、Microsoft.Extensions.Configuration.AzureAppConfiguration预览版)和非核心依赖(如PlayFabAllSDK),测试最小化项目是否能正常运行,排查是否由第三方包引发冲突。 - 确认Rider运行配置工作目录:确保运行配置的工作目录设置为项目根目录,避免因路径错误导致依赖文件无法找到。
内容的提问来源于stack exchange,提问作者Bilal Akil
相关产品推荐
相关产品推荐

