我正在将一个名为“Bridge”的 Azure 函数部署到 Azure,目标是 .NET 6。该项目引用了我编写的一个名为“DBLibrary”的类库,该库目标是 .NET Standard 2.1。 Azure Function 可以在我的 PC 上本地运行,不会出现运行时错误。
当我将 Azure Function 发布到 Azure 时,我在 Azure 门户中看到“函数运行时错误”,其中显示:
Could not load file or assembly 'System.ComponentModel, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
我不直接针对 System.ComponentModel,并且我没有看到任何 nuget feed 中提供的“System.ComponentModel”的 nuget 包版本 6.0.0。为什么 Azure 函数要查找此版本 6.0.0 的 System.ComponentModel?如果该版本确实存在,为什么 Azure Functions 找不到它?
以下是“桥”Azure 功能的 csproj 的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DBLibrary\DBLibrary.csproj" />
</ItemGroup>
</Project>
以下是 Azure Function 项目引用的“DBLibrary”类库的 csproj 的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>
</Project>
我尝试在 Azure Functions csproj 中将 _FunctionsSkipCleanOutput 设置为 true,因为这是作为 nuget 包解析问题的潜在解决方案提供的: https://github.com/Azure/azure-functions-host/issues/7061 该解决方案并没有改变我在 Azure 门户中看到的运行时错误。
最佳答案
如果您已升级到 .NET 6.0,则需要执行以下操作来解决此错误。
清理解决方案,然后重建,它应该在本地工作,也应该在 Azure 中工作
关于azure - 为什么 .NET 6 上的 Azure Function 寻找 System.ComponentModel 版本 6.0.0.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71255419/