skip to Main Content

On a newly created consumption tier Azure Function App, when I deploy even a basic Function app created in Visual studio 2022, I get below error message on Function app in Azure portal and I cant call the FA URL.

System.Private.CoreLib: Could not load file or assembly
‘System.Net.Primitives, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a’. The system cannot find the file
specified.

enter image description here

Solution on below 2 pages have not helped

Azure Function: System.Private.CoreLib: Could not load file or assembly 'System.ComponentModel.Annotations…'

Azure Function, EF Core, Can't load ComponentModel.Annotations 4.2.0.0

What is the reason for this error and how do I fix it?

Update-
Below is the Function App code. This is the standard code that is generated when an empty HTTP trigger function app is created.

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace FunctionApp1
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            return new OkObjectResult(responseMessage);
        }
    }
}

.csproj file code

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <RootNamespace>func_trial</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

2

Answers


  1. If you creating in-process function then you can directly create it in azure portal too.

    Make sure you have below packages in .csproj file.

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <RootNamespace>_78886216</RootNamespace>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
      </ItemGroup>
      <ItemGroup>
        <None Update="host.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
      </ItemGroup>
    </Project>
    

    Then try to execute your function locally to get the expected response before deploying it to function app.

    Also, create an in-process function app to deploy your code to it.

    I am also using the default Http triggered function code and able to deploy it successfully to the function app.

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. Cause

    It looks like you are using an old Azure Functions template, which is likely designed for the deprecated "in-process" model of Functions. This has since been replaced by "isolated worker" Functions.

    "in-process" in .NET 8 application hosts is not enabled by default (presumably this is because it’s no longer recommended for new applications.)

    Workaround

    To run the old style "in-process" model in a .NET 8 host, you need to specify some additional options in the application config in Azure:

    • FUNCTIONS_WORKER_RUNTIME must be set with the value "dotnet".
    • FUNCTIONS_EXTENSION_VERSION must be set with the value "~4".
    • FUNCTIONS_INPROC_NET8_ENABLED must be set with the value "1".

    (reference: https://github.com/Azure/azure-functions-host/issues/9951)

    A better solution

    Seeing as you are just starting out on your first Azure Function, I strongly recommend you find some newer templates that use the recommended "isolated worker" Functions. Delete the code you’ve done so far. This will save you wasted effort of learning the older type of Functions – given that they are not the default type and will become obsolete soon.

    To use the correct templates for creating an "isolated worker" Function:

    1. Install the latest Azure Functions Core Tools^2
    2. Execute this in from the command line:
    func init LocalFunctionProj --worker-runtime dotnet-isolated --target-framework net8.0
    

    Full instructions for the above steps can be found here: https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-csharp?tabs=windows%2Cazure-cli

    Final thoughts

    "in-process" Functions were originally missing from .NET 8, because the "isolated worker" Functions replaced them. They were recently added back in again as a temporary feature, but will be finally discontinued in November 2026^1

    You should only consider running the older style of "in-process" Functions if you have written an existing application that already relies heavily on that model. It is possible to retrospectively alter an "in-process" application to use "isolated worker" instead, but the difficulty depends on which types of Bindings you are relying on (see https://learn.microsoft.com/en-gb/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search