How to use Azure function V3 with Entity Framework 6 (exception System.Data.SqlClient: System.Data.SqlClient is not supported on this platform)?

.net-core azure-functions entity-framework-6

Question

I have an Azure V3 app that must call DAL repos built on Entity Framework 6.4 On database initialize I am getting an exception:

System.Data.SqlClient: System.Data.SqlClient is not supported on this platform

That is coming from: System.Data.SqlClient 4.8

public sealed partial class SqlConnection : System.Data.Common.DbConnection, System.ICloneable
{
    public SqlConnection() 
    { 
        throw new System.PlatformNotSupportedException(System.SR.PlatformNotSupported_DataSqlClient)
    }
}

In similar threads the resolution was to downgrade System.Data.SqlClient to version 4.5.1, but in my case the dependency being added by Entity Framework.

Anyone having an idea if it is possible to use Entity Framework 6.4 in Azure function V3 app?

1
2
2/17/2020 3:06:56 PM

Accepted Answer

It seems that it's still a .NET Core 3.0 SDK bug and the following is workaround you could refer to.

Right click on Function project and edit <FunctionAppName>.csproj, add items below to copy related assemblies to output dir.

<ItemGroup>
    <None Include="$(USERPROFILE)\.nuget\packages\system.data.sqlclient\4.6.0\runtimes\win\lib\netcoreapp2.1\System.Data.SqlClient.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
</ItemGroup>

If you'd like to stilluse the .NET Core 3.0 SDK, or need this fix for Functions v3 as well:

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <!-- https://github.com/Azure/azure-functions-host/issues/3568#issuecomment-461182536 -->
    <Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
  </Target>
  <Target Name="PostPublish" BeforeTargets="Publish">
    <!-- https://github.com/Azure/azure-functions-host/issues/3568#issuecomment-461182536 -->
    <Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
    <!-- https://github.com/Azure/azure-functions-vs-build-sdk/issues/333 -->
    <Exec Command="move $(PublishDir)\runtimes $(PublishDir)\bin" />
  </Target>
2
2/18/2020 7:39:25 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