Can't load Entity Framework Core in Azure Function

azure-functions entity-framework-core nuget

Question

I'm trying to use Entity Framework Core with a C# Azure Function, and I'm getting tons of errors with libraries. Starting from the default HTTP trigger template, I created a project.json file containing

{
  "frameworks": {
    "net46":{
      "dependencies": {
        "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0"
      }
    }
   }
}

When the package restore finishes, the compiler can no longer find the extension methods in HttpRequestMessageExtensions:

016-12-21T06:59:24.728 (9,19): error CS1929: 'HttpRequestMessage' does not contain a definition for 'GetQueryNameValuePairs' and the best extension method overload 'HttpRequestMessageExtensions.GetQueryNameValuePairs(HttpRequestMessage)' requires a receiver of type 'HttpRequestMessage'

(and 3 other similar errors).

I don't really need to use those extension methods, and if I delete all code that calls them, instead I get errors about the version of System.Net.Http:

Exception during runtime resolution of assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a': 'System.BadImageFormatException: Cannot load a reference assembly for execution.

at System.Reflection.RuntimeAssembly.nLoadFile(String path, Evidence evidence)

at System.Reflection.Assembly.LoadFile(String path)

at Microsoft.Azure.WebJobs.Script.Description.FunctionMetadataResolver.ResolveAssembly(String assemblyName)

at Microsoft.Azure.WebJobs.Script.Description.FunctionAssemblyLoadContext.ResolveAssembly(String name)

at Microsoft.Azure.WebJobs.Script.Description.FunctionAssemblyLoader.ResolveAssembly(Object sender, ResolveEventArgs args)'

2016-12-21T07:00:00.522 Unable to find assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Are you missing a private assembly file?

When NuGet adds the EntityFrameworkCore package, it installs System.Net.Http version 4.3.0, whereas Azure Functions seems to be looking for the hardcoded version 4.1.1.

I see questions about using EF6 with Azure Functions, but I don't see anything about EF Core.

1
0
12/21/2016 7:12:27 AM

Popular Answer

one solution is changing from Azure Function v2 core to Azure Function v1 framework.

0
3/22/2018 7:01:40 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow