How to resolve error "Microsoft.Azure.WebJobs.Extensions.Http: Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.8.0" when starting azure function

Boris Layvant 0 Reputation points
2024-05-13T02:29:48.0166667+00:00

I created a function using the CLI as per the example in https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-csharp?tabs=windows%2Cazure-cli but it throws the following error upon starting:

Microsoft.Azure.WebJobs.Extensions.Http: Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

Value cannot be null. (Parameter 'provider')

Azure Functions Core Tools version: 4.0.5700
.NET SDK version: 8.0.204
OS: Windows 11 Pro x64

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,394 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MayankBargali-MSFT 69,581 Reputation points
    2024-05-13T05:51:03.1033333+00:00

    @Boris Layvant Thanks for reaching out.

    As per the error it looks like the assembly couldn't found. In the past I do see the same behavior customer reporting the same here. Uninstalling all version of func-cli (core tool) and azure-cli, and then re-installing it with the latest issue fixed this issue.

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others", I'll repost your solution in case you'd like to "Accept" the answer.

    Issue:

    You observed below error creating the azure function using CLI

    Microsoft.Azure.WebJobs.Extensions.Http: Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.`

    `Value cannot be null. (Parameter 'provider')

    Solution:

    Suggested you to uninstall and install the function core tool and azure cli and see if it helps you to resolve the issue. You confirmed that you were able to resolve the issue by clearing nuget cache and re-installing Azure Functions Core Tools following https://github.com/Azure/azure-functions-core-tools/issues/3096

    Thank you again for your time and patience throughout this issue.

    0 comments No comments

  2. Boris Layvant 0 Reputation points
    2024-05-13T12:05:19.97+00:00

    I was able to resolve the issue by clearing nuget cache and re-installing Azure Functions Core Tools thanks to https://github.com/Azure/azure-functions-core-tools/issues/3096