最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Value cannot be null. (Parameter 'provider') Error when running Azure Function locally after upgrading

programmeradmin5浏览0评论

I’ve been working on an ASP.NET Azure Functions project that was initially based on .NET 6. However, I recently switched to macOS and encountered a series of issues:

Visual Studio is not supported on macOS for my current setup. .NET 6 is deprecated and no longer recommended.

To resolve these issues, I decided to upgrade the project and install the .NET 8 SDK. I targeted my project to use .NET 8 and after spending a couple of hours, I managed to get the project to build successfully.

But when I tried to run the project I got into "Value cannot be null. (Parameter 'provider')"

I tried searching the web and tried the following solutions but it didn't work.

  1. Azure Functions Code tools issue 3160 2.Error in Azure Function
  2. Azure Function Binding Register

I’ve been working on an ASP.NET Azure Functions project that was initially based on .NET 6. However, I recently switched to macOS and encountered a series of issues:

Visual Studio is not supported on macOS for my current setup. .NET 6 is deprecated and no longer recommended.

To resolve these issues, I decided to upgrade the project and install the .NET 8 SDK. I targeted my project to use .NET 8 and after spending a couple of hours, I managed to get the project to build successfully.

But when I tried to run the project I got into "Value cannot be null. (Parameter 'provider')"

I tried searching the web and tried the following solutions but it didn't work.

  1. Azure Functions Code tools issue 3160 2.Error in Azure Function
  2. Azure Function Binding Register
Share Improve this question edited Mar 27 at 13:15 Arko 3,9261 gold badge4 silver badges13 bronze badges asked Mar 20 at 9:36 Munawar HussainMunawar Hussain 1 2
  • Welcome to StackOverflow. You need to add more information for people to help. For example, show the minimum code possible from your application, e.g. relevant bits of Program.cs or similar. You also need to give more context for where the error has come from. For example, is there a stack trace to go with it. Thanks. stackoverflow/help/minimal-reproducible-example – Andrew B Commented Mar 20 at 19:32
  • @Munawar Hussain Could you please provide your Program.cs and .csproj files? – Sirra Sneha Commented Mar 27 at 6:53
Add a comment  | 

1 Answer 1

Reset to default 0

Steps to resolve Value cannot be null. (Parameter 'provider') in .NET 8 isolated Azure Functions:

  • Ensure Prerequisites on macOS:
brew install azure/functions/azure-functions-core-tools@4
brew install dotnet
  • Update your function.cs file with this given file:
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using System.Net;

public class HttpExample
{
[Function("HttpExample")]
public HttpResponseData Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
FunctionContext executionContext)
{
var response = req.CreateResponse(HttpStatusCode.OK);
response.WriteString("Hello from .NET 8 Function!");
return response;
}
}
  • Update your .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.17.0"  />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" OutputItemType="Analyzer"  />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0"  />

</ItemGroup>
</Project>

  • Update your Program.cs file:
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddFunctionsWorker();
})
.Build();
host.Run();
  • Update your host.json file:
{
  "version": "2.0"
}
  • Make sure to select dotnet (isolated worker model):

  • Final output in the terminal:

  • Function App successfully started on port:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论