'Dotnet Isolated Azure Function w/ .Net 6 on a Linux consumption plan complaining about 6.0 AspNetCore.App Runtime not being available

I need some help identifying why an Azure Function deployed to a Linux consumption plan is unable to start and complaining about the AspNetCore.App runtime not being available:

Application Insights logs

What I don't quite understand is why would this be referencing RC2 at all. We've isolated the problem to a package dependency (StackExchange.Redis.Extensions.AspNetCore" Version="7.2.1") - if we include this, it breaks the function as deployed in Azure.

Looking at the source for that dependency, it appears that all they're doing is referencing the AspNetCore.App framework reference like so:

https://github.com/imperugo/StackExchange.Redis.Extensions/blob/master/src/aspnet/StackExchange.Redis.Extensions.AspNetCore/StackExchange.Redis.Extensions.AspNetCore.csproj

Note that our Azure Function is able to run .Net 5 with the same project reference (6.x version of the same lib) without any issues.

We're using the CLI to create and deploy the function like so:

Build:

        - task: UseDotNet@2
          inputs:
            version: $(dotNetVersion)
          displayName: Set DotNet Version $(dotNetVersion)                       

        - task: DotNetCoreCLI@2
          inputs:
            command: 'build'
            projects: '**/xyz.Function.OurFunction.csproj'
            arguments: '--configuration $(buildConfiguration) --output $(System.DefaultWorkingDirectory)/func_api'
          displayName: 'Build Function'

Function app creation:

az functionapp create --name $(functionAppName)
   --resource-group $(rg) --consumption-plan-location $(region) 
   --functions-version 4 --os-type Linux --runtime dotnet-isolated 
   --storage-account $(funstorageAccountName) --assign-identity '[system]'

Deployment:

          - task: AzureFunctionApp@1
            inputs:                
              azureSubscription: '$(azureSubscription)'
              appType: 'functionAppLinux'
              appName: '$(functionAppName)'
              package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
              deploymentMethod: 'zipDeploy'
              runtimeStack: 'DOTNET-ISOLATED|6.0'
              appSettings: >-
                -FUNCTIONS_WORKER_RUNTIME dotnet-isolated


Solution 1:[1]

Here's how I solved this epic in my particular case.
In .csproj properties there's <TargetFramework>net5.0</TargetFramework> and <AzureFunctionsVersion>v3</AzureFunctionsVersion>.
Build pipeline uses Pool: Azure Pipelines and Image: ubuntu-latest.

First issue I had was with the Azure Function App Deploy release pipeline task trying to deploy the ZIP artifact. Even if this is the Microsoft recommendation this would hang indefinitely. Therefore there's a Extract files task before, which unzips $(System.DefaultWorkingDirectory)/func/drop/Functions.zip to $(Agent.TempDirectory)/func. func is the artifact source alias in my case.

Imho, the Azure Function App Deploy task is obsolete.
By default, the latest runtime stack that you might pick is DOTNET|3.1 (functionapp v3).
Then, in the task logs, one notices:
Trying to update App Service Application settings.
Data:{"FUNCTIONS_WORKER_RUNTIME":"dotnet","WEBSITES_ENABLE_APP_SERVICE_STORAGE":"true"} .
That's highly unexpected since we are using the out of process model.
Also, the Startup command is empty.
Tried with func azure functionapp publish $(functions-app-name) --no-bundler and dotnet functions.dll to no avail.

msdocs links below:
functional and behavioral differences running on out-of-process compared to .NET class library functions running in-process
.NET isolated project guide
Manual version updates on Linux

Consequently, after deployment, there's a Azure App Service Settings task which sets "FUNCTIONS_WORKER_RUNTIME":"dotnet-isolated".

Then the savior was this guide.

[!NOTE] To be able to publish your isolated function project to either a Windows or a Linux function app in Azure, you must set a value of dotnet-isolated in the remote FUNCTIONS_WORKER_RUNTIME application setting. To support zip deployment and running from the deployment package on Linux, you also need to update the linuxFxVersion site config setting to DOTNET-ISOLATED|6.0.

Deployement is reported successful, function app says Function host is not running.

When I run az functionapp config show --name $(functions-app) --resource-group $(rg) --query 'linuxFxVersion' -o tsv I get DOTNET|3.1.

So I do az functionapp config set --name $(functions-app) --resource-group $(rg) --linux-fx-version 'DOTNET-ISOLATED|5.0' since I am targeting netcore5. This fixed everything and became an Azure CLI task after deployment in the release pipeline.

Solution 2:[2]

In your Function App you need to add the application settings SCM_DO_BUILD_DURING_DEPLOYMENT

In some instances, you may be unable to deploy an app to Linux Azure Functions in the consumption plan. If this occurs, add an application setting named SCM_DO_BUILD_DURING_DEPLOYMENT with a value of 0.

enter image description here

enter image description here

Refer here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 andrei.ciprian
Solution 2