Azure Functions - System.Data.SqlClient is not supported on this platform
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.
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.
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?

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>

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.Dean\AppData\Local\AzureFunctionsTools\Releases\2.14.0\cli\System.Data.SqlClient.dll'. Symbols loaded. 'func.exe' (CoreCLR: clrhost): Loaded 'C:\Dev\Repos\CPDC\AzureFunctions\ProviderTriggers\bin\Debug\netcoreapp2.2\bin\System.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.

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.