Ben
Ben

Reputation: 5705

Can you use v3 Azure Functions with Entity Framework Core 3.0?

I am trying to use EF Core 3 in the latest (preview) version of Azure functions, but I am getting the following error when I try interacting with the database:

System.Private.CoreLib: Exception while executing function: DemoFunction. Microsoft.Data.SqlClient: Microsoft.Data.SqlClient is not supported on this platform.

I have a web app in the same solution that works just fine with the same setup, and there is nothing special about my "platform". This is the output from dotnet --info:

.NET Core SDK (reflecting any global.json): Version:
3.1.100-preview2-014569 Commit: 4bd5d24d87

Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100-preview2-014569\

Host (useful for support): Version: 3.1.0-preview2.19525.6 Commit: 5672978d91

.NET Core SDKs installed: 2.1.801 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.100-preview2-014569 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0-preview2.19528.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0-preview2.19525.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0-preview2.19525.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

I have created a minimal reproduction of the issue here, just start up the functions project and send it an HTTP request (same with the web app).

Is it currently possible to use EF Core 3 with v3 Azure Functions? (FYI I have a v2 Functions app running with EF Core 2.1)

Upvotes: 0

Views: 1406

Answers (2)

Emad Gabriel
Emad Gabriel

Reputation: 3707

Another fix is to move from Microsoft.NET.Sdk.Functions" Version="3.0.8" back to 3.0.7 Reference: https://github.com/Azure/Azure-Functions/issues/1370#issuecomment-654698010

Upvotes: 0

Hury Shen
Hury Shen

Reputation: 15724

This issue has been solved , copy OP's comment , it will be helpful for others have similar issue :

looks like there is a workaround that solves my issue

As a workaround, add the following code to .csproj:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
  </Target>
  <Target Name="PostPublish" BeforeTargets="Publish">
    <Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
  </Target>

Upvotes: 1

Related Questions