I fixed the issue just creating a new Azure Function and updating the code as follows:
Program.cs
changed a bit the structure:
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
})
.Build();
host.Run();
host.json
removed useless code:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
.csproj
changed few versions:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enabled</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Activities\DownloadDocumentsByDatesMediator.cs" />
<Compile Remove="DownloadDocumentsByDates.cs" />
</ItemGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Autofac" Version="8.0.0" />
<!--<PackageReference Include="Microsoft.ApplicationInsights" Version="2.22.0" />-->
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Core.NewtonsoftJson" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Include="Reviso.Authentication" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" OutputItemType="Analyzer"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Tables" Version="1.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RevisoAgyoDataLayer\RevisoAgyoDataLayer.csproj" />
<ProjectReference Include="..\RevisoAgyoModels\RevisoAgyoModels.csproj" />
<ProjectReference Include="..\RevisoAgyoServices\RevisoAgyoServices.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.example.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
Function with endpoint, small changes in the structure:
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Autofac;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask.Client;
using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Http;
using Microsoft.WindowsAzure.Storage.Queue;
using Microsoft.WindowsAzure.Storage;
using RevisoAgyoModels;
using RevisoAgyoServices;
using RevisoAgyoWorkflow.DownloadDocumentsByDates.Implementations;
namespace RevisoAgyoWorkflow.DownloadDocumentsByDates.EntryPoints
{
public class DownloadDocumentsByDates
{
[Function("DownloadDocumentsByDates_HttpStart")]
public static async Task<HttpResponseData> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient starter,
FunctionContext _executionContext)
{
ILogger _logger = _executionContext.GetLogger(nameof(DownloadDocumentsByDates));
var cosmosDbConnectionString = Environment.GetEnvironmentVariable("CosmosDb_connectionString");
var downloadDocumentQueueConnectionString = Environment.GetEnvironmentVariable("DownloadDocument_connectionString");
var downloadDocumentQueueName = Environment.GetEnvironmentVariable("DownloadDocument_queueName");
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(downloadDocumentQueueConnectionString);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference(downloadDocumentQueueName);
var globalConfig = GlobalConfig.Instance(() =>
new AutofacConfig()
.DefaultConfig()
.ConfigCosmosClient(new CosmosClient(cosmosDbConnectionString))
.ConfigDownloadDocumentQueueStorage(queue)
.ConfigTelemetryExecutionContextProvider(_executionContext)
.BuildContainer());
var _telemetry = globalConfig.Container.Resolve<ITelemetry>();
var input = req.ReadFromJsonAsync<DownloadDocumentsByDatesParams>().Result;
var executionContext = new TelemetryExecutionContext(_executionContext);
string instanceId = null;
IPurchaseInvoicesDownloadingService _purchaseInvoicesDownloadingService = null;
...
}
}
}
I do not know what exactly fixed the issue, but I made these changes based on what I had the new Azure Function and it worked.