【发布时间】: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