azure - 为什么 .NET 6 上的 Azure Function 寻找 System.ComponentModel 版本 6.0.0.0?

标签 azure .net-core azure-functions .net-6.0 system.componentmodel

我正在将一个名为“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,则需要执行以下操作来解决此错误。

  1. 将 cs proj 更新到 v4 enter image description here

  2. 将 Azure 中的函数应用中的配置更新为以下内容 enter image description here

  3. 更新解决方案的所有 nuget 包

清理解决方案,然后重建,它应该在本地工作,也应该在 Azure 中工作

关于azure - 为什么 .NET 6 上的 Azure Function 寻找 System.ComponentModel 版本 6.0.0.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71255419/

相关文章:

asp.net - ASP Core、Identity Server 4 和 Angular 2 中的外部提供商登录

java - 有没有办法使用Java中的Azure Functions的@EventHubTrigger来获取事件(EventHub)的标题数据?

Azure Frontdoor 多路径路由不适用于存储静态 Web 应用程序

.net - 如何在 ASP.NET Core 测试中 stub /模拟服务

.net-core - 我们可以保护仅使用 aspnet 身份的 dotnet core 2.0 React App 吗?

build - 使用 Azure 函数为 Windows 版本构建软件?

python - 如何在Python Azure函数中解析 "Could not load type ' Microsoft.Azure.WebJobs.ParameterBindingData'"?

azure - Azure IOT Edge 设备可以连接到多个 Azure IOT 集线器吗?

python - Http响应错误: This request is not authorized to perform this operation using this permission in Python Azure Function

c# - 尝试替换 connectionStrings 元素以在 Visual Studio Team Services 中进行持续部署