【问题标题】:Azure Functions 1.0.7 giving Could not load file or assembly error with EF Core 2Azure Functions 1.0.7 给出 EF Core 2 无法加载文件或程序集错误
【发布时间】:2018-06-12 20:41:31
【问题描述】:

我正在尝试将某些功能移至 Azure Functions。为 EF Core 2 代码创建了一个项目,并将其引用到 Azure Functions 项目。将 EF Core+SQLServer 块包添加到 Azure Functions 项目。当函数试图执行时,这是屏幕上的错误。我可以看到 Microsoft.EntityFrameworkCore 程序集与我们的 azure 函数 dll 位于同一目录中。

谁能解释为什么找不到它以及如何解决这个问题?

[1/3/2018 6:49:56 AM] A ScriptHost error has occurred
[1/3/2018 6:49:56 AM] Exception while executing function: Accounting. AS.Jobs: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[1/3/2018 6:49:56 AM] Exception while executing function: Accounting
[1/3/2018 6:49:56 AM] Exception while executing function: Accounting. AS.Jobs: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[1/3/2018 6:49:56 AM] Function completed (Failure, Id=56ba500b-7c3a-45c1-a9eb-8be4d52d1592, Duration=159ms)
[1/3/2018 6:49:56 AM]
[1/3/2018 6:49:56 AM] Executed 'Accounting' (Failed, Id=56ba500b-7c3a-45c1-a9eb-8be4d52d1592)
[1/3/2018 6:49:56 AM] System.Private.CoreLib: Exception while executing function: Accounting. AS.Jobs: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
[1/3/2018 6:49:56 AM]   Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is '56ba500b-7c3a-45c1-a9eb-8be4d52d1592'
[1/3/2018 6:49:56 AM] System.Private.CoreLib: Exception while executing function: Accounting. AS.Jobs: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.  

更新:2018 年 1 月 3 日
我已经安装了 VS 2017 15.5.2,我正在 VS 中构建它。

这是我从 VS 运行函数主机时的输出。

[1/4/2018 3:47:03 AM] Host configuration file read:
[1/4/2018 3:47:03 AM] {
[1/4/2018 3:47:03 AM] }
[1/4/2018 3:47:04 AM] Generating 1 job function(s)
[1/4/2018 3:47:04 AM] Starting Host (HostId=jlt03-962556955, Version=2.0.11353.0, ProcessId=21200, Debug=False, Attempt=0, FunctionsExtensionVersion=)
[1/4/2018 3:47:04 AM] Found the following functions:
[1/4/2018 3:47:04 AM] Jobs.Accounting.Run
[1/4/2018 3:47:04 AM]
Listening on http://localhost:7071/  

【问题讨论】:

  • 您是否正在编译 .NET Standard 2.0 库并在 Functions 运行时的 v2(预览版)版本上运行?
  • 我相信是的,我怎么确定呢?所有这些多平台的东西都让它有点麻烦。
  • csproj 中检查TargetFramework 并运行func -v 以查看运行时版本
  • TargetFramework 对于 Azure Function 项目是 netstandard2.0,对于 EF Core 2 项目是 netstandard2.0;net462。我应该从哪里运行 func -v?
  • 我用更多信息更新了这个问题,希望能有所帮助。我应该如何为 EF Core 引用我的类程序集?我对每个项目都有两种不同的解决方案,我只是将 Azure Function 项目指向 EF Core 类的 bin\release\netstandard2.0\{assembly} 的输出目录。

标签: azure entity-framework-core azure-functions azure-web-app-service


【解决方案1】:

经过更多搜索,我发现了这个GitHub posted issue。这是我在这里看到的完全相同的问题。显然这是 Azure Functions 1.0.7 和 EF Core 2.0.1 的问题。

我必须将 AF 恢复到 1.0.6 并且我还必须将 EF Core 恢复到 2.0.0。之后函数按预期执行。

我将监控 GitHub 问题并在确认已修复后更新此答案。

更新
Azure Functions Core Tools 2.1.0 版本现已修复此问题。
https://github.com/Azure/app-service-announcements/issues/109

【讨论】:

    【解决方案2】:

    对我有用的是删除 bin 文件夹下的所有文件夹并构建应用程序!!

    【讨论】:

      猜你喜欢
      • 2017-07-25
      • 2016-12-16
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      相关资源
      最近更新 更多