I cannot succed in starting my Azure Function. I got the following error:
[2024-04-25T09:22:29.421Z] Found
C:Usersgdifronzosource_C#AE.Resp.Device.Sync
AE.Resp.Device.SyncAE.Resp.Device.SyncAE
.Resp.Device.Sync.csproj. Using for user secrets file configuration.
[2024-04-25T09:22:30.766Z] A host error has occurred during startup operation
'd5c1ddb1-1e25-406a-b64c-ef69bf086ab4'.
[2024-04-25T09:22:30.768Z] Microsoft.Azure.WebJobs.Script: Did not find functions with
language [dotnet-isolated].
[2024-04-25T09:22:30.786Z] Failed to stop host instance '8db57ba1-9d37-44cd-a3d9-
e6e01699e700'.
[2024-04-25T09:22:30.788Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
My local.settings.json is the following:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"FhirServerUrl": "https://xxxxxxxxxxxx.azurewebsites.net",
"TimeTriggerSchedule": "0 */5 * * *",
"MaximumExecutionTime": 21600,
"MongoDbConnectionString": "mongodb+srv://xxxxxxxxxxx",
"MongoDbThumbprint": "xxxxxxxx"
}
}
Azurite local emulator is on. My Program.cs in the Azure Function project is:
IHostBuilder builder = new HostBuilder().ConfigureFunctionsWebApplication();
var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile("local.settings.json", true, true)
.Build();
X509Certificate2 mongoCertificate;
string mongoConnectionString = configuration.GetValue<string>
("MongoDbConnectionString")
??
throw new CertificateNotFoundException("Unable to load configuration with key
'MongoDbConnectionString'");
try
{
mongoCertificate =
Utils.LoadCertificate(configuration.GetRequiredSection("MongoDbThumbprint").Value);
}
catch
{
throw;
}
MongoDBService mongoDBService = new(mongoConnectionString, mongoCertificate);
builder.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.AddSingleton<IDeviceSyncService, DeviceSyncService>();
services.AddSingleton(mongoDBService.CreateRepository<ExecutionParameters>
("deviceSync"));
});
IHost host = builder.Build();
host.Run();
The functios is:
private readonly ILogger _logger = loggerFactory.CreateLogger<DeviceSyncFunction>();
private readonly IDeviceSyncService _deviceSyncService = deviceSyncService;
[Function("DeviceSyncFunction")]
public void Run([TimerTrigger("%TimerExpression%", RunOnStartup = true)] TimerInfo
timerInfo)
{
try
{
_logger.LogInformation($"Timer trigger function executed at: {DateTime.UtcNow}
UTC");
_deviceSyncService.GenerateDevices();
_logger.LogInformation($"Timer trigger function terminated at: {DateTime.UtcNow}
UTC");
}
catch (OperationCanceledException opex)
{
_logger.LogWarning(opex, opex.Message);
}
catch (FhirOperationException ex)
{
_logger.LogError(ex, ex.Message, ex.StackTrace);
}
catch (Exception ex)
{
_logger.LogCritical(ex, ex.Message);
}
}
And the project file .cproj is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<None Include="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
<PackageReference
Include="Microsoft.Azure.Functions.Worker.Extensions.Http"Version="3.1.0" />
<PackageReference
Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore"
Version="1.2.1"/>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer"
Version="4.3.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2"/>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService"
Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights"
Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference
Include="..AE.Resp.Device.Sync.ModelAE.Resp.Device.Sync.Model.csproj" />
<ProjectReference
Include="..AE.Resp.Device.Sync.ServiceAE.Resp.Device.Sync.Service.csproj" />
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
I can’t even figure out what’s happening. As I said, azurite local emulator is on, I don’t have any problem with it. ChatGPT says that the configuration is correct. I’m trying to troubleshoot, but I cannot find anything clear. When I try to start-up another Azure Function with the same settings and dependencies (I’ve copied and past dependencies on project file and also the Program.cs and local.settings are similar), I succed. So the problem seem not an hidden wrong settings on my local computer. Any idea?