Search code examples
c#asp.netazureazure-functionspublish

Azure Function - Functions not showing


I have created a new Azure Function and created it in Azure. The function also runs flawlessly locally. However, as soon as I publish the function, the function endpoints are not displayed in the Azure portal and cannot be called up. All functions are also correctly stored in the Kudu portal of the function. However, the following error is displayed in the activity log: Screenshot from activity log Configurations from Azure Function General configurations

I have already tried to recreate the function and have also tried to adjust the configurations. However, these are always reset to the default value after a publish.


Solution

    • Function App settings should match with the settings in your local.settings.json.

    local.settings.json:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",// or add same storage connection string which has been added in the Azure function app in portal.
            "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
        }
    }
    
    • Check if the deployment is creating an extra folder under site/wwwroot folder.
    • Build and run the functions locally before deploying the function to Azure.
    • Delete the existing files under Site/wwwroot and deploy the function again.

    I have created a .NET 8 Isolated Azure function and deployed to Azure function app.

    • Compare below configuration with yours and check if anything is missing.

    • Configure function Timeout in host.json:

    {
        "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          },
          "enableLiveMetricsFilters": true
        }
      },
      "functionTimeout": "00:30:00"
    }
    

    Function.cs:

    • Check the Function attribute.
     [Function("Function1")]
     public IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
     {
         _logger.LogInformation("C# HTTP trigger function processed a request.");
         return new OkObjectResult("Welcome to Azure Functions!");
     }
    

    .csproj:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
      </PropertyGroup>
      <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
        <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
      </ItemGroup>
      <ItemGroup>
        <None Update="host.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
      </ItemGroup>
      <ItemGroup>
        <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
      </ItemGroup>
    </Project>
    
    • Try selecting Self-Contained as Development mode while creating publish profile:

    enter image description here

    Portal:

    enter image description here

    Configuration of Function App after deployment:

    enter image description here

    You can also deploy using func azure functionapp publish <functionapp_name>.