I already opened an issue in Azure/azure-functions-host
and I have a repo with the repro steps, but I'm posting this here in case there is something inherently wrong with what I'm doing, or someone has already stumbled open this issue.
My goal: I want to run in an azure function some code that lives in a class library in an existing visual studio solution.
This code happens to use entity framework core in order to read and write to a SQL Server database.
While trying to isolate the issues I was facing, I ended up with the following scenario:
Repro steps:
In Visual Studio: File > New > Project > Azure Functions
Select Azure Functions v2 Preview (.NET Core)
Select Http trigger
Select Storage Emulator
Select Access rights Function
Install using nuget Microsoft.EntityFrameworkCore
version 2.0.2
Add an invocation to anything from the EFCore
package
In my case I added the following line:
log.Info(typeof(DbContext).AssemblyQualifiedName);
Ensure the azure storage emulator is running
Run the function from visual studio (F5
)
Hit the url printed in the console
Expected behavior: along with the default behavior of the example Http trigger
function I expect to see the following line printed with each invocation:
Microsoft.EntityFrameworkCore.DbContext, Microsoft.EntityFrameworkCore, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
Actual behavior: the app throws an exception at runtime and outputs the following
[11-Apr-18 6:33:59 AM] Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=6faabfd8-eb96-4d71-906c-940028a7978a)
[11-Apr-18 6:33:59 AM] Executed 'Function1' (Failed, Id=6faabfd8-eb96-4d71-906c-940028a7978a)
[11-Apr-18 6:33:59 AM] System.Private.CoreLib: Exception while executing function: Function1. FunctionApp1: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.0.2.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.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Current conjecture: while researching this issue I found something that might be related:
The Azure functions runtime already has a set of packages available, one of those being Newtonsoft.Json
in a specific version. In the case a newer version of Newtonsoft.Json
is referenced from the project a similar behavior is observed.
Workaround: For Microsoft.EntityFrameworkCore
roll back to version 2.0.1. Don't know if it is a known EFCore issue, but rolling back to 2.0.1 helped med with the exact same issue.
User contributions licensed under CC BY-SA 3.0