runtime icon indicating copy to clipboard operation
runtime copied to clipboard

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

Open rohan3usturge opened this issue 8 years ago • 43 comments

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.

rohan3usturge avatar Nov 20 '18 06:11 rohan3usturge

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.

karelz avatar Nov 26 '18 17:11 karelz

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 ?

bartdk-be avatar Dec 16 '18 11:12 bartdk-be

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?

mike1880 avatar Dec 17 '18 10:12 mike1880

Same issue here with SqlDataClient 4.6.0

gauravagarwal28 avatar Dec 20 '18 10:12 gauravagarwal28

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.

karelz avatar Dec 20 '18 19:12 karelz

Can you provide the entire stack trace?

davidfowl avatar Dec 21 '18 04:12 davidfowl

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

bartdk-be avatar Dec 21 '18 07:12 bartdk-be

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?

mike1880 avatar Dec 21 '18 11:12 mike1880

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.

Wraith2 avatar Dec 21 '18 12:12 Wraith2

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.

djangojazz avatar Dec 21 '18 22:12 djangojazz

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.

ryancole avatar Jan 04 '19 02:01 ryancole

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 avatar Jan 15 '19 01:01 danimal521

@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 avatar Jan 15 '19 01:01 ryancole

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

ss123

danimal521 avatar Jan 15 '19 01:01 danimal521

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...

kvaes avatar Jan 18 '19 19:01 kvaes

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

kvaes avatar Jan 18 '19 19:01 kvaes

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.

Wraith2 avatar Jan 18 '19 20:01 Wraith2

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?

kvaes avatar Jan 21 '19 09:01 kvaes

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.

mike1880 avatar Jan 21 '19 09:01 mike1880

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

anyonehasmypermission avatar Aug 15 '19 14:08 anyonehasmypermission