Cannot get my .net 6 isolated function app on a linux consumption plan working

Peter Bons 156 Reputation points
2023-06-07T16:27:42.9766667+00:00

Context

I have developed an azure function app with an http triggered azure function. It is written in C#, targetting .Net 6. I have deployed the function app to a linux function app on a consumption plan using a bicep template.

Problem

The Azure Portal does not show the function:

User's image

and the streaming log shows this:

User's image

Code

The function looks like this:

using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace FunctionApp
{
    public static class Function
    {
        [Function("MyFunction")]
        public static HttpResponseData Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]  HttpRequestData req,
            FunctionContext executionContext)
        {
            var logger = executionContext.GetLogger(nameof(Function));
            logger.LogInformation("C# HTTP trigger function processed a request.");

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

            response.WriteString("Hello World!");

            return response;
        }
    }
}

The relevant part of the bicep template looks like this:

resource myFunctionApp 'Microsoft.Web/sites@2022-09-01' = {
  name: 'expechofunctionapp'
  location: location
  kind: 'functionapp,linux'
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    serverFarmId: myAppPlan.id
    httpsOnly: true
    reserved: true
    siteConfig: {
      linuxFxVersion: 'DOTNET-ISOLATED|6.0'
      appSettings: [
        {
          name: 'AzureWebJobsStorage'
          value: 'DefaultEndpointsProtocol=https;AccountName=${myFunctionStorage.name};EndpointSuffix=${az.environment().suffixes.storage};AccountKey=${myFunctionStorage.listKeys().keys[0].value}'
        }
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~4'
        }
        {
          name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
          value: myAppInsights.properties.InstrumentationKey
        }
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'dotnet-isolated'
        }
        {
          name: 'dotnetenv'
          value: environment
        }
        {
          name: 'WEBSITE_RUN_FROM_PACKAGE'
          value: '${myFunctionStorage.properties.primaryEndpoints.blob}azurefunction/FunctionApp_Binaries.zip'
        }
      ]
    }
  }
}

Steps taken

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Developer technologies C#
{count} votes

Accepted answer
  1. MuthuKumaranMurugaachari-MSFT 22,441 Reputation points Moderator
    2023-06-13T16:16:10.7933333+00:00

    Peter Bons thanks for posting your question in Microsoft Q&A. I followed bicep template https://learn.microsoft.com/en-us/samples/azure-samples/function-app-arm-templates/function-app-linux-consumption/ and edited runtime as dotnet-isolated as you have and were able to deploy it successfully.

    Initially I faced the same issue when file structure inside the zip was incorrect. Please refer to https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-class-library?tabs=v4%2Ccmd#functions-class-library-project and make sure the files contain bin, host.json etc. are inside the zip (not inside another folder; just zip all files inside \bin\publish instead of zipping the publish folder).

    I hope this helps and let me know if you have any questions.


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.