Runtime: Azure Functions - System.Data.SqlClient is not supported on this platform

Created on 20 Nov 2018  路  43Comments  路  Source: dotnet/runtime

Hi Team,

When using System.Data.SqlClient ( 4.6.0-preview-versions ) with azure functions, following exceptions is being thrown.

4.6.0-preview3-27014-02

System.Private.CoreLib: One or more errors occurred. (System.Data.SqlClient is not supported on this platform.). System.Data.SqlClient: System.Data.SqlClient is not supported on this platform

Downgrading the version to 4.5.1 works fine.

Tried with 2.2.100-preview2-009404 SDK too, still getting the same exception.

I am using the preview version because we need to use the AAD accesstoken property on SqlConnection Object.

area-System.Data.SqlClient question

Most helpful comment

Got the problem with 4.7.0 today. And the Microsoft.Data.SqlClient gives me the same error

All 43 comments

I don't think Azure Functions supports preview versions of .NET Core.
Unless it has self-contained app option, you need to wait for the right .NET Core version to be supported there first.

I'm using the latest (non-preview) version, but still the azure function is throwing the exception.


--> Has a dependency on 4.6.0

I assume it's no longer preview ?

Same problem here, SqlDataClient 4.6.0 is no longer preview ("latest stable"), is it possible to reopen this issue or do I need to open a new one?

Same issue here with SqlDataClient 4.6.0

We need more information - first I would recommend to find out what is the Azure Functions platform. Which .NET Framework or .NET Core version.
That should be enough to reproduce the problem locally without Azure Functions.
Then we can decide where the problem is and how to address it.

Can you provide the entire stack trace?

image

There is no extra stacktrace available except this : System.Private.CoreLib: Exception while executing function: Function1. System.Data.SqlClient: System.Data.SqlClient is not supported on this platform.

  • Create new Azure Functions project (using VS2017 15.9.4)
  • Core 2.2
  • Add nugets to EFCore and EFCore Sql Server
  • Try to add something to a dbset and save changes to context

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.2</TargetFramework> <AzureFunctionsVersion>v2</AzureFunctionsVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> </Project>

image

Mine is bare ADO.NET:

VS 15.9.3, Core SDK 2.2.101
Create new Azure Function V2, queue trigger
Create SQL connection string in local.settings.json
Add Microsoft.Extensions.Configuration and System.Data.SqlClient via nuget
Read in the connection string and open the connection:

var config = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("local.settings.json", true, false)
.AddEnvironmentVariables()
.Build();
var connectionString = config.GetConnectionString("SqlConnectionString");
Console.WriteLine(myQueueItem);
SqlConnection connection = new SqlConnection(connectionString);

I get a runtime error when it tries to open the connection, the final entries in Output window are:

'func.exe' (CoreCLR: clrhost): Loaded 'C:\Users\M.DeanAppData\LocalAzureFunctionsTools\Releases\2.14.0\cliSystem.Data.SqlClient.dll'. Symbols loaded.
'func.exe' (CoreCLR: clrhost): Loaded 'C:\Dev\Repos\CPDCAzureFunctions\ProviderTriggers\bin\Debug\netcoreapp2.2\binSystem.Data.SqlClient.dll'. Symbols loaded.
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Exception thrown: 'System.PlatformNotSupportedException' in System.Data.SqlClient.dll
Exception thrown: 'System.PlatformNotSupportedException' in System.Private.CoreLib.dll
Exception thrown: 'System.PlatformNotSupportedException' in System.Private.CoreLib.dll
An unhandled exception of type 'System.PlatformNotSupportedException' occurred in System.Private.CoreLib.dll
System.Data.SqlClient is not supported on this platform.

It works fine with SqlDataClient 4.5.1

Edit to add - from above it appears the exception is thrown from SqlDataClient so it's maybe one for the ADO.Net team?

I tried to create an Azure Function to test this and I found I've only got one template in VS 2017 for azure functions and it sets up a project that uses Netfx not Corefx. So I went looking and found this: https://docs.microsoft.com/en-us/azure/azure-functions/functions-versions and the transition from 1.x to 2.x guidelines which state that you should change the project to contain:

<TargetFramework>netstandard2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>

If you make that change when restoring nuget packages the build system will give you netstandard binary versions of dependencies. Netstandard isn't a real runtime so the binaries for it are reference only, they contain the public surface area but as you've seen they don't have an implementation. To get the implementation you have to restore using a TFM for a real runtime, in this case you'd want to use netcoreapp2.2 I think.

I have the same issue as bartdk-be. I upgraded my Azure Function from .NET Standard 2.0 to .NET Core 2.2 today and out of the blue this error now happens. It is running a package that is running Entity Framework Core 2.2. I have tried manually installing via Nuget System.Data.SqlClient for 4.6 and then going back versions. It just won't work at all at this point. I am thinking about going back till it gets sorted out. The interesting thing in my case is I have a .NET Standard library project I used it for prior due to Azure Functions previously being on .NET Standard. I upgraded it as well to be .NET Core 2.2 but no dice.

I too am receiving this error. My Functions application is not on .NET Core 2.2, however. I saw the other issue that .NET Core 2.2 is not yet supported on Functions host. I'm using .NET Core 2.1, which is what the VS template created. I'm trying to use System.Data.SqlClient version 4.6.0 like the others in this thread. The exception contains no other exceptions except for the one stating that the client is not supported on this platform. Here is the stack trace ...

   at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at League.Data.Sql.LeagueSqlSession..ctor(String connectionString) in C:\Users\Ryan\projects\esaleague\src\League.Data.Sql\LeagueSqlSession.cs:line 25

Not much to it.

Edit: This StackOverflow post seems to acknowledge the issue, mentions it's being tracked and recommends a workaround that resolved the exception for me.

Hello, anymore progress on this? I am getting the issue as well.

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <AzureFunctionsVersion>v2</AzureFunctionsVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" /> <PackageReference Include="System.Data.SqlClient" Version="4.6.0"/>

@danimal521 I was able to resolve the issue by downgrading the System.Data.SqlClient library by one release. It seems to have been in an issue in the release.

@ryancole that totally worked! I used 4.5.1 seemed to be the last prod build.

ss123

4.5.1 might "solve" (workaround) the issue as stated in the title.
Reverting back form the 4.6 will result in the issue that one will not be able to use AAD auth ;

Severity    Code    Description Project File    Line    Suppression State
Error   CS1061  'SqlConnection' does not contain a definition for 'AccessToken' and no accessible extension method 'AccessToken' accepting a first argument of type 'SqlConnection' could be found (are you missing a using directive or an assembly reference?)

So using AAD auth towards Azure SQL is not possible in combination with Azure Functions...

Same issue when using the 4.70-preview-18571.3 (preview) release.

Did you try the target framework moniker thing I suggested earlier? I've been working on sqlclient and having no trouble with restores but i'm using netcoreapp as my target. if you use netstandard I think you'll get the stub verison with PNSE's in it.

Mine is already set to the netcoreapp...

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <AzureFunctionsVersion>V2</AzureFunctionsVersion>
  </PropertyGroup>

Or am I missing the ball on what you're trying to point me to?

Did you try the target framework moniker thing I suggested earlier? I've been working on sqlclient and having no trouble with restores but i'm using netcoreapp as my target. if you use netstandard I think you'll get the stub verison with PNSE's in it.

Makes no difference. The V2 function templates give you those settings by default anyway.

@ryancole @danimal521 I downloaded 4.6.1 (prod release), the error is gone. Thanks for sharing the solution.

Got the problem with 4.7.0 today. And the Microsoft.Data.SqlClient gives me the same error

Got the problem with 4.7.0 today. And the Microsoft.Data.SqlClient gives me the same error

I experienced the same thing with 4.7.0 + higher versions.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.30-beta2" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.0-preview2.19523.17" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

As you can see, I've tried updating to the latest "preview" packages for "Microsoft.NET.Sdk.Functions" and "System.Data.SqlClient."

@ryancole @danimal521 I downloaded 4.6.1 (prod release), the error is gone. Thanks for sharing the solution.

I can confirm. Downgrading to 4.6.1 resolved this issue for me as well.

This needs to be reopened, nothing is in preview anymore outside of core 3 functions support and this is occurring across the board for anything about 4.6.1.

@davidfowl Are you volunteering?

No, I'm explaining where the issue should be filed because it's not a corefx problem.

Updating the people in this thread to note that this issue is also opened in the repo @davidfowl linked above: https://github.com/Azure/azure-functions-host/issues/3903 , with a couple workarounds. If you're still having issues, I'd suggest looking / commenting there!

having the same issue with PackageReference Include="System.Data.SqlClient" Version="4.7.0" but worked with 4.6.1

Same issue here: "System.Data.SqlClient" Version="4.7.0". Quite disappointing. We have been evaluating .Net Core, Azure functions for a large enterprise project. Strange issues with other .Net Core-based libraries as well. Things just look too flaky for a long term commitment.

@glennc

Has this been fixed? I am trying to use System.Data.SqlClient in Azure function v3. Downgrading to 4.6.1 does not work for me.

This local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "FUNCTIONS_V2_COMPATIBILITY_MODE": "true"
  }
}

and additional targets:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
[...]
  </ItemGroup>
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
    <Exec Command="copy $(OutDir)local.settings.json $(OutDir)bin\local.settings.json" />
  </Target>
  <Target Name="PostPublish" BeforeTargets="Publish">
    <Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
  </Target>
</Project>

"fixed" this for me.

Just adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" helped

Just adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" helped

Worked for me as well... Thank you!

Awesome. Worked for me too! Thanks!

Adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" worked! Thank you @vitalybibikov

Thak you @vitalybibikov

@cheenamalhotra is there any action required here? Can you please help evaluate.

We've verified that Microsoft.Data.SqlClient is supported with Azure Functions all versions (v1, v2 and v3).

A demo app that can be tested with deployment is available here:
https://github.com/cheenamalhotra/azurefunctions-sqlclient-example

Same should also work with System.Data.SqlClient and is also verified above.
I don't think any action item is needed from our end on the same.

If there's any open support remaining on the same, please feel free to redirect to dotnet/sqlclient!
This issue can be closed here.

@cheenamalhotra - I took this sample project upgraded to the Azure functions SDK to the latest (3.0.3), updated the version of Azure functions in the project file to use v3 and then replaced Microsoft.Data.SqlClient with System.Data.SqlClient and then added this to the test function:

SqlConnectionStringBuilder connStrBldr = new SqlConnectionStringBuilder
{
ApplicationName = "TestProject",
ConnectTimeout = 10,
LoadBalanceTimeout = 10
};

and I got this error, which suggests that System.Data.SqlClient and not working properly. In my tests if I use Microsoft.Data.SqlClient it does work

_

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

_

We can麓t migrate our code over to use Microsoft.Data.SqlClient because we are relying on https://www.nuget.org/packages/Microsoft.Azure.SqlDatabase.ElasticScale.Client/ which relies on System.Data.SqlClient

Fyi.., setting "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" does solve this

Closing this issue as we don't reproduce any problems with SqlClient, but the problems emerge due to Azure Functions SDK existing issues.

For anyone facing this issue, please create a new issue with reproducible app provided in dotnet/sqlclient repository if any problems are found with SqlClient libraries.

Adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" worked!

Was this page helpful?
0 / 5 - 0 ratings