After updating an Azure Function to .NET8, it fails with "Could not load file or assembly 'System.Console, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified."

CMagoun 15 Reputation points
2024-08-26T13:55:28.3933333+00:00

I tried to upgrade an Azure Function to .NET8 and the latest Azure Function runtime. It fails each run with the following error:

Could not load file or assembly 'System.Console, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

I can get this function to execute locally, but not when it is deployed to Azure.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
Developer technologies | .NET | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hong Lam 10 Reputation points
    2025-03-11T04:53:25.9233333+00:00

    Refer to: https://stackoverflow.com/questions/77501626/upgrading-my-azure-function-to-net8-fails-with-the-error-could-not-load-file-or
    Solved by adding ”FUNCTIONS_INPROC_NET8_ENABLED": "1" to local.settings.json:

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "FUNCTIONS_INPROC_NET8_ENABLED": "1",
            "FUNCTIONS_WORKER_RUNTIME": "dotnet"
        }
    }
    
    2 people found this answer helpful.
    0 comments No comments

  2. Pinaki Ghatak 5,600 Reputation points Microsoft Employee Volunteer Moderator
    2024-08-28T16:24:34.44+00:00

    Hello @CMagoun

    It seems like the error is caused by a missing assembly reference. The System.Consoleassembly is not included in the Azure Functions runtime.

    To resolve this issue, you can try the following steps:

    1. Add a reference to the System.Console NuGet package in your Azure Function project.
    2. Ensure that the package is included in the deployment package by checking the "Copy Local" property of the reference. Set it to "True" if it is not already.
    3. If the issue persists, try adding a binding redirect to the app.config file of your Azure Function project.

    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.


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.