Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rohan3usturge opened this issue Nov 20, 2018 · 43 comments
Closed
Labels
area-System.Data.SqlClient question Answer questions and provide assistance, not an issue with source code or documentation.
Milestone

Comments

@rohan3usturge
Copy link

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.

@karelz
Copy link
Member

karelz commented Nov 26, 2018

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 karelz closed this as completed Nov 26, 2018
@bartdk-be
Copy link

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 ?

@mike1880
Copy link

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?

@gauravagarwal28
Copy link

Same issue here with SqlDataClient 4.6.0

@karelz
Copy link
Member

karelz commented Dec 20, 2018

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.

@davidfowl
Copy link
Member

Can you provide the entire stack trace?

@bartdk-be
Copy link

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

@mike1880
Copy link

mike1880 commented Dec 21, 2018

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?

@Wraith2
Copy link
Contributor

Wraith2 commented Dec 21, 2018

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.

@djangojazz
Copy link

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.

@ryancole
Copy link

ryancole commented Jan 4, 2019

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.

@danimal521
Copy link

danimal521 commented Jan 15, 2019

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"/>

@ryancole
Copy link

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

@danimal521
Copy link

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

ss123

@kvaes
Copy link

kvaes commented Jan 18, 2019

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
Copy link

kvaes commented Jan 18, 2019

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

@Wraith2
Copy link
Contributor

Wraith2 commented Jan 18, 2019

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.

@kvaes
Copy link

kvaes commented Jan 21, 2019

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?

@mike1880
Copy link

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.

@anyonehasmypermission
Copy link

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

@Ericmas001
Copy link

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

@haydenhancock
Copy link

haydenhancock commented Nov 5, 2019

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

@haydenhancock
Copy link

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

@dustensalinas
Copy link

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
Copy link
Member

It should be moved to https://github.com/Azure/azure-functions-host/

@onionhammer
Copy link

@davidfowl Are you volunteering?

@davidfowl
Copy link
Member

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

@nofield
Copy link

nofield commented Nov 25, 2019

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

@Psuban
Copy link

Psuban commented Nov 26, 2019

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

@vologar
Copy link

vologar commented Nov 27, 2019

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.

@danmoseley
Copy link
Member

@glennc

@ravibha
Copy link

ravibha commented Dec 27, 2019

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.

@timvdh
Copy link

timvdh commented Dec 27, 2019

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.

@vitalybibikov
Copy link

Just adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" helped

@andreoromera
Copy link

Just adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" helped

Worked for me as well... Thank you!

@ravibha
Copy link

ravibha commented Jan 3, 2020

Awesome. Worked for me too! Thanks!

@bmontalvo
Copy link

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

@v1n3k0
Copy link

v1n3k0 commented Jan 22, 2020

Thak you @vitalybibikov

@danmoseley danmoseley reopened this Jan 22, 2020
@danmoseley
Copy link
Member

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

@cheenamalhotra
Copy link
Member

cheenamalhotra commented Jan 22, 2020

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.

@icelandgrecian
Copy link

icelandgrecian commented Jan 31, 2020

@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

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@cheenamalhotra
Copy link
Member

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.

@PraveenNTechi
Copy link

Adding "FUNCTIONS_V2_COMPATIBILITY_MODE": "true" worked!

@ghost ghost locked as resolved and limited conversation to collaborators Dec 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Data.SqlClient question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests