I'm trying to create an azure function that needs to access a database. I have a .netstandard 2.0 library that contains all the database stuff (it has Microsoft.EntityFrameworkCore.Tools
and Microsoft.EntityFrameworkCore.SqlServer
Nuget packages and created all the related classes with Scaffold-DbContext
). My azure function (queue triggered) has a reference to that library and it has Nuget packages Microsoft.EntityFrameworkCore.SqlServer
and Microsoft.EntityFrameworkCore
. Everything builds, but when it runs and the queue triggers the functions it complains:
[1/18/2019 3:53:49 PM] A ScriptHost error has occurred
[1/18/2019 3:53:49 PM] Exception while executing function: MyFunction. MyProcessor: Could not load file or assembly 'Microsoft.EntityFrameworkCore, Version=2.2.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.2.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
which happens here (because it I just remove the using
block, then it runs fine, but obviously doesn't do anything useful):
[FunctionName("MyFunction")]
public static void Run([QueueTrigger("my-items", Connection = "queueConnection")]string myQueueItem, TraceWriter log)
{
using (var ctx = new MyDotNetStandardLibary.Models.MyEFContext())
{
//...
}
log.Info($"C# Queue trigger function processed: {myQueueItem}");
}
The bin
folder does contain Microsoft.EntityFrameworkCore.dll
and it looks like it's the right version, so why won't it load it? I had a similar problem with JSON.net, but ended up just giving up on even using it and worked around it. But I need EF. What am I missing about getting an Azure function to load dependencies?
User contributions licensed under CC BY-SA 3.0