I'm unable to get my Azure Function App to work in .NET 8.
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using <namespace>.FunctionApps.Extensions;
using Serilog;
var environment = Environment.GetEnvironmentVariable("AZURE_FUNCTIONS_ENVIRONMENT");
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("host.json", optional: true, reloadOnChange: true)
.AddJsonFile($"host.{environment}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
Log.Logger = logger;
var builder = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.RegisterServices(configuration, logger);
});
var host = builder.Build();
host.Run();
I get the following Exception message when I hit the host.Run();
line
System.InvalidOperationException: 'The gRPC channel URI 'http://:' could not be parsed.'
The function I am trying to run is a Service Bus FA subscribing to Azure SB Queue
using Microsoft.Azure.Functions.Worker;
using <namespace>.Common.Helpers;
using <namespace>.InterimSolutionModels.Extensions;
using <namespace>.Models.DispatchMessages;
using <namespace>.ServiceBus;
using Serilog;
namespace <namespace>.FunctionApps.Functions.DistributionList
{
public class DeleteDistributionList(ILogger logger)
{
private readonly ILogger _logger = logger;
[Function(nameof(DeleteDistributionList))]
[ServiceBusOutput(QueueNames.InterimProcessing, Connection = "ServiceBusConnectionString")]
//public void Run([ServiceBusTrigger(QueueNames.Group.DistibutionListQueue.DeleteDistibutionList, Connection = "ServiceBusConnectionString")] ServiceBusReceivedMessage message)
public string Run([ServiceBusTrigger(QueueNames.Group.DistibutionListQueue.DeleteDistibutionList, Connection = "ServiceBusConnectionString")] DistributionListDeleteMessage message)
{
_logger.Information($"Received Message: {message}");
var interimDistibutionListDelete = message.ToInterimModel();
var outPutJson = JsonHelper.ToJson(interimDistibutionListDelete);
return outPutJson;
}
}
}
My project file is as follows
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.1" />
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.15.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="<Path/Namespace>.Common.csproj" />
<ProjectReference Include="..\<Path/Namespace>.ServiceBus.csproj" />
<ProjectReference Include="..\<Path/Namespace>.Service.csproj" />
</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 updated the project templates and recreated the FA project in case that was an issue. I'm not sure if I missed a step somewhere (Azurite setup for example), if I am facing an issue from one of the libraries (I have found other places with the same parsing http exception but no solution) or I plain don't understand how this works yet...
What's getting me is that I am not using gRPC, so this has to be related to hosting / possibly my startup code.
I am getting an error when attempting to start my Azure Function App (.NET 8/Isolated worked model) locally (VS 2022.The function I am trying to run is a Service Bus FA subscribing to Azure SB Queue
Below is how I use Serilog and Azure Service Bus Function App:
Program.cs:
using Microsoft.Extensions.Hosting;
using Serilog;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(services =>
{
Log.Logger = new LoggerConfiguration()
.CreateLogger();
})
.Build();
host.Run();
Function.cs:
using System;
using Azure.Messaging.ServiceBus;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace FunctionApp113
{
public class Function1
{
private readonly ILogger<Function1> _logger;
public Function1(ILogger<Function1> logger)
{
_logger = logger;
}
[Function(nameof(Function1))]
public void Run([ServiceBusTrigger("rithwik", Connection = "rithcon")] ServiceBusReceivedMessage message)
{
_logger.LogInformation("Message ID: {id}", message.MessageId);
_logger.LogInformation("Message Body: {body}", message.Body);
_logger.LogWarning("Message Content-Type: {contentType}", message.ContentType);
_logger.LogCritical("Hello Rithwik");
}
}
}
host.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"FunctionApp113.Function1": "Information"
}
}
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"rithcon": "Endpoint=sb://hiservice.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=chP9VP9/i7+ASbBs1ErI=",
"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=42f478bf99;IngestionEndpoint=https://centralindia-0.in.applicationinsights.azure.com/;LiveEndpoint=https://centralindia.livediagnostics.monitor.azure.com/"
}
}
csproj:
<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.20.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.12.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
</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>
Output:
After message is send to service bus queue then it is getting triggered like below: