首页 > 解决方案 > 即使启用了自动绑定,也找不到程序集

问题描述

我有一个失败的 Azure 函数,出现找不到程序集错误

System.ComponentModel.Annotations, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

在我的 Azure 函数和包含代码的类库中都正确引用了这个包

我在两个项目文件中都有这个

  <PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
  </PropertyGroup>

我该如何解决这个非常令人沮丧的问题?

我已经引用了 System.ComponentModel.Annotations 包

关于如何在 Azure 函数中进行程序集重定向似乎没有太多内容

我在 .NET Core 3.1 系统中使用 Azure Functions V3

保罗

标签: c#asp.net-corenugetasp.net-core-3.1

解决方案


可能是因为 nugget 的版本与生成的库的版本不匹配。您可以尝试以下方法:

1.从包管理控制台做:

Get-Project –All | Add-BindingRedirect

assemblyBinding在配置文件中重新生成配置

2.如果没有修复,则手动添加绑定重定向。根据您需要指定的版本进行更改

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.ComponentModel.Annotations"
                      publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="4.1.0.0" newVersion="4.0.0.0"/>
  </dependentAssembly>

oldVersion:指定最初请求的程序集版本

newVersion:指定要使用的程序集版本


推荐阅读