The error is populating when you are using ASP .NET Core Integration in Isolated function which is to have ConfigureFunctionsWebApplication() and its related packages in program.cs and .csproj file respectively.
Azure Isolated Function comes with or without integration. If you are comfortable to use Isolated Azure Function without the ASP .NET core integration then use ConfigureFunctionsWorkerDefaults(). You should have given code in program.cs file.
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();
host.Run();
To support this, you should have given packages in .csproj file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>_79181186</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.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>
I have made the below changes to the function file which worked for me.
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net;
namespace _79181186
{
public class TestFunction
{
private readonly ILogger<TestFunction> _logger;
public TestFunction(ILogger<TestFunction> logger)
{
_logger = logger;
}
[Function("test-function")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
try
{
var response = req.CreateResponse(HttpStatusCode.OK);
await response.WriteStringAsync("Request processed successfully.");
return response;
}
catch (Exception ex)
{
var errorResponse = req.CreateResponse(HttpStatusCode.BadRequest);
await errorResponse.WriteStringAsync($"An error occurred: {ex.Message}");
return errorResponse;
}
}
}
}
The request body, I am sending is of size 30MB.
Azure Functions Core Tools
Core Tools Version: 4.0.6610 Commit hash: N/A +0d55b5d7efe83d85d2b5c6e0b0a9c1b213e96256 (64-bit)
Function Runtime Version: 4.1036.1.23224
[2024-11-14T08:37:36.560Z] Found C:\Users\*****\79181186\79181186.csproj. Using for user secrets file configuration.
[2024-11-14T08:37:40.597Z] Azure Functions .NET Worker (PID: 6272) initialized in debug mode. Waiting for debugger to attach...
[2024-11-14T08:37:40.664Z] Worker process started and initialized.
Functions:
test-function: [POST] http://localhost:7256/api/test-function
For detailed output, run func with --verbose flag.
[2024-11-14T08:37:50.923Z] Executing 'Functions.test-function' (Reason='This function was programmatically called via the host APIs.', Id=72b320ab-75fd-44a6-a513-be5742ae2c08)
[2024-11-14T08:37:51.486Z] C# HTTP trigger function processed a request.
[2024-11-14T08:37:51.548Z] Executed 'Functions.test-function' (Succeeded, Id=72b320ab-75fd-44a6-a513-be5742ae2c08, Duration=1229ms)
The same has worked in portal as well.

[Function("test-function")] public async Task<IActionResult> TestFunction( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "test/function")] HttpRequestData req) { try { return new OkResult(); } catch (Exception ex) { Logger.LogError(ex, ex.Message); return new BadRequestObjectResult(ex.Message); } }