azure-functions-host: Cannot use System.Data.SqlClient 4.6.0 and greater on functions V2.

If you follow this tutorial, it will fail: https://docs.microsoft.com/en-us/azure/azure-functions/functions-scenario-database-table-cleanup

It fails with the error:

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

This is because you’ll get 4.6.0 or later, which seems to result in the above error. Downgrading to 4.5.1 will resolve the issue.

The same version (4.6.0) works fine in a .NET Core 2.1 console app. We need to figure out why its failing in a function app. I suspect it has something to do with the fact that we are loading it via reflection, and there are some issues, see here: https://github.com/dotnet/corefx/issues/24229

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 30 (11 by maintainers)

Most upvoted comments

@fabiocav Any update on this? This is still not working for me.

An update on this… recent enhancements address this (and the liked issue #3568). Those enhancements will be deployed with the next release.

Assigning this to sprint 40 for validation.

Before it’s fixed, try this workaround.

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

 <!-- For publish -->
  <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>

  <!-- For local debug -->
  <Target Name="CopyToBin" BeforeTargets="Build">
    <Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.data.sqlclient\4.6.0\runtimes\win\lib\netcoreapp2.1\System.Data.SqlClient.dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>

Link one identical issue. And #3568 is mitigated by similar solution, just for your reference @paulbatum .

To clarify, what version of the core tools and SDK are you using when you run into the issue?

Turns out I was using 3.0.1740. I use Rider and the Azure plugin updated with pre-release. I reverted back to 2.7.1724 and the error has gone away.

For anyone else using Rider with the Azure plugin - I think there is something wrong with the latest release as it used a pre-release of the Azure Core Tools and I have that unchecked - but it still grabbed one from GitHub anyway.

@rajpamamull Keep an eye on https://github.com/Azure/app-service-announcements/issues - we’ll announce our next deployment there. Should be within the next two weeks.

@jdbenn the needed tooling changes went live with the last release. Assigning this to the current sprint for the host work and to have this scenario validated.

@fabiocav Any thoughts on why folks are still reporting issues here? Reopening while we investigate.