Welcome to Microsoft Q&A! Thanks for posting the question.
As you have mentioned that the function runs locally but not in azure then I will suggest you to check dot net runtime and SDK's that are running locally as well in azure.
To run the command in azure function you can navigate to kudo console (Navigating to yourfunctionname.scm.azurewebsites.net --> Debug Console Option) and run the below commands:
dotnet --list-sdks
dotnet --list-runtimes
Please verify the targeting version whether it is 3.1 or 5.0? The error could be as the function doesn't support v5 packages. Please make sure that you have removed the v5 dependency nuget packages and make sure your packages are all v3 that supported by functions.
Sharing discussion to not mix .NET Core 3.1 and .NET5 packages when working with Azure Functions.