-
Notifications
You must be signed in to change notification settings - Fork 447
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
Unable to access SqlClient in Azure app function V3 #5950
Comments
Getting "Microsoft.Data.SqlClient is not supported on this platform" too, with Azure app function V3 and .NET Core 3.1 Renamed folder runtimes to bin; and have placed function.deps.json in bin folder... no help, same error |
I just ran into this issue as well. In my case, it runs fine locally on Windows. It also seems to run fine on Azure with Windows or Linux consumption plans. However, any attempt to run in a linux container, either locally or in Azure, fails with the platform not supported error. I noticed that the dockerfiles for the containers were recently updated to the latest function runtime Azure/azure-functions-docker#241, but I don't think the updated images have been published yet. I wonder if the older runtime has something to do with it? You can find a simple reproduction case here: https://github.com/npnelson/AzureFunctionSqlClientDemo (be sure to read the repo's Readme if you try it out) |
After more investigation, when I build in Release with Visual Studio/Docker it works, but in Debug/Docker it doesn't and all production scenarios for me work. |
For those hitting this:
I just tried the @npnelson repro and it worked locally and deployed in both Debug and Release. Locally I'm running 3.0.13139.0 and in Azure I'm running 3.0.13353.0. Is everyone else running into this only on Docker+Linux+Debug? Or are there other configurations that aren't working? I'm setting up a repro for this scenario now... |
Hello @brettsam I'm running into the same errors as described in this thread. Below are different scenarios I'm running which encounter same exception. I've also pointed out where exception is not encountered when executing same code. I'll attempt to soon provide a repro project to show issue. The scenario we have is specific to when Azure Client function is restarted and an Orchestration Function attempts to retry after restart. I've attempted to call out three scenarios below showing error behaviour and also successful behaviour. For the scenarios below I used a SqlCommand to query a table that did not exist to force an exception within Activity Function 1. This would result in exception being thrown and expectation is Orchestration to handle retries. As a workaround for now - we are invoking the SqlConnectionStringBuilder class on Startup to force DLL to load. This seems to load correct DLL for all scenarios. Details
Scenario A - Exception - After retry and function restart
Scenario B - Successful Behaviour - Retry with no function restart
Scenario C - Successful Behaviour - Retry orchestration works after restart when new orchestration created before retry
Attachments:
|
Hey @brettsam , |
@brettsam @brendonatkins Having a very similar issue here: #6094 It is intermittent but popping up just often enough that we are getting very nervous about it. |
@brendonatkins thank you! When you say "Client Function is then shut down" in your failure scenario -- how is the app shutting down? And you're doing all this locally? I'm trying a bunch of combinations of things to try to reproduce this and everything seems to work as expected for me (I never see a Were you (or anyone else, for that matter) able to get a small repro together that I can run and try it? Having it fail locally is ideal b/c then I can debug into it directly and figure out what's happening. |
@brettsam We are not able to reproduce this issue locally. This is the full exception (with our application portion redacted) that we get in Azure. Please note this is a very intermittent issue, but it pops up often enough to be very concerning. I assume it has to do with the VM environment that gets unlucky enough to run the code:
|
@brettsam It looks like this is what is happening: https://github.com/dotnet/SqlClient/wiki/Frequently-Asked-Questions#11-why-do-i-get-a-platformnotsupported-exception-when-my-application-hits-a-sqlclient-method Basically, the Nuget package has a fallback DLL that stubs the constructor of @brendonatkins Your suggestion seems interesting:
Does this mean that if inside the Startup class I new up a SqlConnectionStringBuilder, but do not even use it to initialize my SqlConnection (since we are using EF Core via AddDbContext) then I should be able to work around the error? |
@npnelson -- thanks again for the repro. When you say this fails when running locally in Docker, is that when launching the app via Visual Studio? I think that VS is doing something odd and the @APIWT -- is it possible for you to share your .csproj file? That'd help narrow down exactly what libraries, SDKs, etc, you are using. Also, if you could share your Function App name (either explicitly or privately), I can see if I find anything from the backend logs. And again, if anyone has a simple repro that shows this failing, I'd love to see it -- I'm still not able to repro this (outside of the "launching Docker via VS" scenario from @npnelson). It's also useful to check via kudu (go to |
@brettsam Thank you so much for getting back to me. This is the invocation ID and timestamp:
Our region is East US 2. Here is my Functions CSPROJ (with project name redacted):
This file is our Directory.Build.targets file for the Functions application (note the workaround for publishing extensions.json properly and the associated Github issue):
Here is the Infrastructure.csproj:
And here is Data.csproj:
|
@brettsam Yes, you are correct - only when launching the app via Visual Studio. I swear I previously had this problem in Azure environments, but at this point, I'd say I am an unreliable eyewitness. I think the functions SDK and Runtime updated while I was trying to get this to work which may have corrected the issue. @APIWT You might want to try upgrading your Microsoft.NET.Sdk.Functions to the latest (3.0.7) if you can, that has a shot at fixing your problem, although the fact that your issue is intermittent is a bit perplexing. |
@npnelson I'll try that out and let you know how it goes :) Yes the intermittent part of it is what scares us. |
@APIWT -- can you check if you have a This all has to do with whether or not we can find the native deployed assembly -- it's really odd if this only happens sometimes. |
@brettsam We do indeed have a
Also, we will totally upgrade to the latest |
Hello @brettsam Thank you for getting back. I've attached a repro project which simplifies our app down just to the core concern I raised earlier. I tried several variations which did not require actually querying a DB but it seems the reproducable error pattern is when attempt is made to query on database, activity function fails, and then application is restarted before durable function retries. I've attached a README with steps to reproduce. As for your questions. I am running locally using Visual Studio F5 build and run command. And to shutdown using Ctrl+C within function application runtime window. DurablePlatformNotFoundRepro.zip Let me know if you have issues reproducing. I tried to automate the scenario but to ensure speedy response I thought best just to pass through would I could. Thank you Brendon |
I'm having a similar issue, and it's trivial to replicate. I've attached a set of sample projects that demonstrate the issue, read on for the explanation and/or a way to recreate the scenario if you don't trust my download: AzureFunctionsSqlClientBug.zip Firstly, create a .NET Core 3.1 Azure Functions v3 project with an HttpTrigger. Leave everything as-is.
Now, create a solution containing a .NET Core Console or Web Application project and make that project reference the same Class Library created above. Then, add the same This demonstrates that the issue is not with .NET Core or ASP.NET Core or the SqlClient library, but manifestly within the Azure Functions runtime. |
@IanKemp I think in your case, you might need to use |
Ah, very interesting. For the .NET Core and ASP.NET Core solutions, the Visual Studio Modules windows shows the following as I'd expect: But the Azure Functions run shows an additional That additional DLL corresponds with the one shipped with If I overwrite it with the 4.8.0 version from my function's I think somebody forgot to update |
@APIWT Can you point me to any documentation stating this? I've searched extensively and haven't found anything. If that's true then it essentially prohibits anyone with a Framework project that uses SqlClient, from using that project in a Functions V3 app, without refactoring the Framework project to use |
Okay, this is definitely an assembly load problem, but I'm no longer sure if it's an Azure Functions or SqlClient one. Note how in the .NET Core console/ASP.NET Core modules shown in my previous comment, the SqlClient DLL is being loaded from But in the Azure Functions modules, that DLL is being loaded directly from the The DLL in So what's happening in the .NET Core console/ASP.NET Core success case:
But in the Azure Functions failure case:
|
@IanKemp To be honest, I don't really know if it is a requirement. I just know that when we migrated our ASP.NET Core application from 2.2 to 3.0 we weren't able to compile unless we did. And since we use EF Core as part of our functions application, it was a change we assumed would carry forward into both projects. This is what we read at the time: |
@IanKemp Do you have a Startup class? If so, what happens if you add some code like this in the
I realize how ridiculous this looks, but I am curious if it forces the correct assembly to load. |
It does! ... kinda... Unfortunately, although the correct assembly is loaded, the application still fails with:
If only I knew what specific file (framework source stepping doesn't help, since by the time that exception is thrown the path of the file it's trying to load has been optimised away...) |
That's a bummer. This is kind of what we are trying (although we are using |
(focusing on @brendonatkins repro first) -- Thanks for that readme! I was able to reproduce this now. It seems like something is happening when Durable Functions starts the function from a retry -- but now I have something to try to debug. Will come back with my findings. |
@brettsam That's awesome news! Thank you and best of luck. |
Thanks to the magic of .NET Core assembly loading trace flags, some more critical info: For the .NET Core console solution:
...
...
But for the Azure Function sln:
...
...
The .deps files entries for |
@IanKemp Dumb question, but is the test that you have just run with or without the |
@brendonatkins -- you're a hero! Your repro helped us figure out the issue here and I've split this out into a separate issue -- #6143. Follow along there for the fix and any possible workarounds (I'm looking into a workaround now). |
The traces are identical in both scenarios. |
In summary for anyone experiencing this issue with
(If you're not on Windows x64 I can't help you, but there are other DLLs in Then it all Just Works like it should have from the start - no need for extra code to bootstrap |
@brettsam I am running into this issue pretty easily. I just created a brand new v3 ServiceBusTrigger Function with docker support and added Entity Framework 3.1 and when I try to query the DB, I get the error. Here is my .csproj file:
Here is my docker file: FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build FROM build AS publish FROM base AS final Any assistance will be helpful. Right now the only way for me to get this to work is to downgrade to function v2 |
@brettsam if you are referring to this, then yes. It gives me:
Is there anything else I should be trying? One more thing - This seems to be a Linux issue. When I run this locally outside of docker there are no errors. |
The issue I have is the same that @npnelson is having - here Does not work locally in DEBUG on docker, does work locally in RELEASE on docker. |
@amtandon You are almost certainly stuck waiting for 3.0.13904 to roll out to Azure globally. Then you'll have to wait for Microsoft to push a new version of the Then you'll have to wait for Microsoft to push a new version of the core tools, since that's tied to the functions runtime version, and again if versions aren't in sync it all goes to the proverbial location on a handbasket. So basically, you're gonna be waiting for a while. |
Yeah, at least it will work in Docker when we deploy to AKS. For local debugging, I can do without docker. |
@amtandon -- can you spawn a separate issue with the details for how I can repro this? This issue is getting pretty overloaded. Mention me there and I'll jump over and look. I'm wondering if it's the same issue that I saw when using the VS Docker tools? See comment here: #5950 (comment). But we'll follow up in the new issue. |
@brettsam I have opened issue #6303. Ir definitely looks like it is an issue with VS Docker tools as mentioned in comment [#5950 (comment)] |
I think that we've fixed all issues identified in this thread (with the exception of the "debugging in VS with Docker" scenario in #6303) and that the fixes have all been released now. I'm going to close this issue -- if you run into this again please open a new issue (and feel free to tag me in it) so we can start a fresh investigation. |
With the latest Azure function V3 I'm having trouble using Sql client.
Tried System.Data.SqlClient & Microsoft.Data.SqlClient packages, both throws error.
Attaching both the error logs.
System.Data.SqlClient_ErrorLog.txt
Microsoft.Data.SqlClient_ErrorLog.txt
Please provide the following:
Repro steps
Error1:
Provide the steps required to reproduce the problem:
By default System.Data.SqlClient package being available, try to establish a database connection.
This will throw below error.
"Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)"
Error2:
Install Microsoft.Data.SqlClient package (Latest version 1.1.2), try to establish a database connection.
Following error message is thrown.
"Microsoft.Data.SqlClient is not supported on this platform."
Related information
Provide any related information
The text was updated successfully, but these errors were encountered: