【问题标题】:Azure function 5 and EF Core 5 Could not load file or assembly > Microsoft.Extensions.DependencyInjection.AbstractionsAzure 函数 5 和 EF Core 5 无法加载文件或程序集 > Microsoft.Extensions.DependencyInjection.Abstractions
【发布时间】:2021-10-09 22:10:03
【问题描述】:

System.IO.FileNotFoundException:无法加载文件或程序集 'Microsoft.Extensions.DependencyInjection.Abstractions, 版本=5.0.0.0,文化=中性,PublicKeyToken=adb9793829ddae60'。 系统找不到指定的文件。

在 azure devops 管道中运行测试时出现上述错误,但在本地运行时却没有。在本地一切正常。

我相信当基类在第 15 行尝试使用 EF Core 5 初始化 DB Context 时会发生错误。

代码栈:

已启用 Azure 功能隔​​离 .Net 5

EF Core 5

有人可以帮我理解为什么会这样吗?下面是测试项目中引用的包的截图。

【问题讨论】:

  • 它们应该是相同的版本:Change Abstractions to 5.0.2
  • 即使在将 EF Core、依赖项和抽象更改为 5 .0.0 之后,我也遇到了同样的错误
  • 下面的答案有帮助吗?
  • @singhh-msft 不。我必须将它的所有内容降级到 3.1。不能冒险使用 .Net 5 进行生产
  • 还有其他问题吗?还是只有这个还没有解决?

标签: c# .net-core azure-functions asp.net-core-5.0 ef-core-5.0


【解决方案1】:

这可能有两个原因,AFAIK:

  • 确保项目中的所有 Nuget 包都相互兼容。检查Microsoft.Extensions.DependencyInjection.Abstractions 是否具有与项目中所有其他 Nuget 包兼容的版本。查找依赖项的一种方法是在 Nuget 包管理器中:

  • 确保这些包包含在项目的.csproj 文件中:

    <ItemGroup>
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.1" OutputItemType="Analyzer" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.0.0" />
      <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.4" />
      <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.4">
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        <PrivateAssets>all</PrivateAssets>
      </PackageReference>
      <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
      <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
      <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
      <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
      <PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
    </ItemGroup>
    

【讨论】:

  • 我遇到了类似的问题,降级 Worker 包并不能解决问题。
猜你喜欢
  • 2021-01-06
  • 2017-10-15
  • 2023-03-21
  • 2021-03-06
  • 1970-01-01
  • 2018-10-13
  • 2018-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多