Azure functions using dotnet-isolated runtime do not run and are not visible in the Azure Portal

1.4k Views Asked by At

I have an Azure function project on the .Net 7 runtime that I've configured to run in dotnet-isolated mode. It runs successfully locally when I publish it through Visual Studio, using Azurite as the storage emulated.

The problem is that when I deploy through my Gitlab/Octopus CI/CD pipeline, the function is not displayed in the "Functions" tab of the Function App in the portal and the Azure runtime doesn't seem to be able to "see" the isolated .exe that is created by my build process and it does not run the function.

For context: I'm using Kubernetes-based runners on a self-hosted Gitlab instance. This is used for project builds. I have set the containers to pull the mcr.microsoft.com/dotnet/sdk:7.0 image, which should be the only dependencies required to build the Function App.

Ultimately, the pipeline is configured to run dotnet commands to produce a build:

- dotnet restore --force --no-cache
- dotnet build --configuration Release

And then the build is packaged and sent to Octopus deploy for deployment. I have not found dotnet publish to ever produce a working app that Azure Function Apps can run, so I've ommitted it.

This pipeline has worked up until now with non-isolated Function apps and a windows-based runner, but something about dotnet-isolated Function apps and Linux-based runners is causing issues at runtime.

I've also noticed that without the --runtime parameter set to win, the runner only produces Linux-targeted apps. No .exe file is present in the build.

The hosting environment is an EP1 tier Windows Azure App Function.

Here is the project file for the Function project

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <ImplicitUsings>enable</ImplicitUsings>
    <OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.16.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.1.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.11.0" />
    <PackageReference Include="OpenAI" Version="1.7.2" />
</ItemGroup>
<ItemGroup>
    <ProjectReference Include="..\Core.Jobs\Core.Jobs.csproj" />
    <ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
    <None Update="host.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="appsettings.json">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
    <None Update="nrdiag.exe">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="nrdiag_arm64.exe">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="nrdiag_x64.exe">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
</ItemGroup>

And the FUNCTIONS_WORKER_RUNTIME setting in our config file:

{
"IsEncrypted": false,
"Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"ConnectionStrings": {
}

}

3

There are 3 best solutions below

0
SiddheshDesai On

I tried deploying the Function with an alternative method by using the zip command in my Gitlab pipeline like below:-

My repository with Function trigger zip:-

enter image description here

variables:
  AZURE_CLIENT_ID: xxxxx838-xxx1435cb
  AZURE_CLIENT_SECRET: xxxxxxx8313-xxxifbLE
  AZURE_TENANT_ID: xxxxx-xxx-xx038592395
  AZURE_WEBAPP_NAME: siliconfunc653

stages:
  - deploy

deploy:
  stage: deploy
  image: mcr.microsoft.com/dotnet/sdk:7.0
  script:
    - curl -sL https://aka.ms/InstallAzureCLIDeb | bash
    - apt-get install curl && curl -sL https://deb.nodesource.com/setup_12.x | bash -
    - apt-get install nodejs
    - npm install -g azure-functions-core-tools@3 --unsafe-perm true
    - az login --service-principal -u $AZURE_CLIENT_ID -p $AZURE_CLIENT_SECRET --tenant $AZURE_TENANT_ID
    - func azure functionapp publish $AZURE_WEBAPP_NAME --csharp
  only:
    - main

Instead of using func azure function-app-name publish command you can directly use the command below in the yml script above:-

 az functionapp deployment source config-zip --name $AZURE_WEBAPP_NAME --resource-group Insights_Test --src function.zip

Also, Make sure you have the following settings added in the Function Configuration:-

enter image description here

enter image description here

Reference:-

.gitlab-ci.yml · main · Wai Lin / gitlab-ci-Azure-Function · GitLab

Gitlab CI script to deploy a Azure Function - DEV Community

0
JimiSweden On

Not sure if this is answering the original question; but I had a similar issue when upgrading a project from "netcoreapp3.1" to .net 7.

Functions worked locally but was not loading in Azure function app (Windows on App Service Environment v2). What i did to reproduce this error was to upgrade nuget packages in an already upgraded .net 7 function (upgraded earlier this year)

The following azure.functions was updated; and then the functions didnt load again.
(Note: I havent read up on the documentation of what is updated and might be breaking changes, nor have I investigated dependencies to internal libraries with dependencies on Microsoft.Azure)

  • According to the questions details I assume the issue might be in

    Microsoft.Azure.Functions.Worker or .sdk

From: (working)

Microsoft.Azure.Functions.Worker" Version="1.14.0"
Microsoft.Azure.Functions.Worker.Core" Version="1.12.0"
Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13"
Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.7.0"
Microsoft.Azure.Functions.Worker.Sdk" Version="1.10.0"

TO: (not working)

Microsoft.Azure.Functions.Worker" Version="1.20.0"
Microsoft.Azure.Functions.Worker.Core" Version="1.16.0"

Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0"   
Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.14.1"
Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.1"
0
Md. Sabbir Ahamed On

To fix the issue into my end, I just update the project.csproj with following

<PublishReadyToRun>true</PublishReadyToRun>

<RuntimeIdentifier>win-x86</RuntimeIdentifier>

After deploying and restart again I see functions are available

Can checkout the following docs

https://learn.microsoft.com/en-us/answers/questions/1300902/cannot-get-my-net-6-isolated-function-app-on-a-lin

https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library?tabs=v4%2Ccmd#functions-class-library-project