Unable to load Entity Framework Core into C# azure function

5

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:

  1. In Visual Studio: File > New > Project > Azure Functions

  2. Select Azure Functions v2 Preview (.NET Core)

  3. Select Http trigger

  4. Select Storage Emulator

  5. Select Access rights Function

  6. Install using nuget Microsoft.EntityFrameworkCore version 2.0.2

  7. Add an invocation to anything from the EFCore package

    In my case I added the following line:

    log.Info(typeof(DbContext).AssemblyQualifiedName);
    
  8. Ensure the azure storage emulator is running

  9. Run the function from visual studio (F5)

  10. 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.

Here's a StackOverflow question. Here's a github issue

c#
azure
entity-framework-core
azure-functions
asked on Stack Overflow Apr 11, 2018 by Maximo Dominguez • edited Apr 13, 2018 by Maximo Dominguez

1 Answer

4

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.

answered on Stack Overflow Apr 13, 2018 by Morten Frederiksen

User contributions licensed under CC BY-SA 3.0