0

I'm making an Http triggered Azure Function v4 in .NET 4.8 with Microsoft.NET.Sdk.Functions 1.0.24 and my test endpoints that do not reference any other assemblies work correctly.

However, when I try to use a method in a referenced assembly, I get the following error:

Could not load type 'System.Data.SqlClient.SqlParameter' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

at Example.Data.PeopleBiz.GetPersonByUserName(String username)
at Example.OperationFunc.DoItFunction.DoItEndpoint(HttpRequestMessage req, TraceWriter log)

I'm sorry I cannot post code due to confidentiality and the scale of the solution. I realize this probably restricts the assistance to people who have overcome this specific issue. Has anyone gotten a large .NET 4.8 Azure Function to work? Running locally in VS2022, this function works flawlessly.

Here are some relevant environment vars:

{
    "name": "FUNCTIONS_EXTENSION_VERSION",
    "value": "~4",
    "slotSetting": false
},
{
    "name": "FUNCTIONS_WORKER_RUNTIME",
    "value": "dotnet-isolated",
    "slotSetting": false
}
1
  • Can you provide an sample code to see how your code looks and configuration(packages and its version) too. Commented Jul 1, 2024 at 5:50

1 Answer 1

0

You probably need to explicitly add a reference to the correct version of System.Data.SqlClient, which is the package that holds SqlParameter.

The version referenced in your error message (4.0.0.0) is not a version that is available on NuGet for System.Data.SqlClient. I think the fact this runs fine locally is probably because you have SQL or SQL Types installed locally.

Sign up to request clarification or add additional context in comments.

1 Comment

It's like whac-a-mole. System.Data.SqlClient was already there, so I copied System.Data to the bin on azure and that error went away but 2 more popped up about "mscorlib" and "System.Web". The interesting thing is that the function will run without having to manually add these DLLs when FUNCTIONS_EXTENSION_VERSION = "~1". I'm considering running on v1 and then try to get our code base migrated to .NET 8 and function v4 some time in the next 2 years. I'm having a terrible time getting v4 running with .NET 4.8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.