We want to receive service bus messages from our azure service bus using ServiceBusTrigger, locally in Visual Studio 2022. For Authentication, we use Managed Identity.
Context
- .NET Core 3.1
- An AD-user with valid credentials which is logged in, in Visual Studio 2022
- Installed Nuget-Packages:
Microsoft.Azure.Functions.Extensions (1.1.0),
Microsoft.Azure.WebJobs.Extensions.ServiceBus (5.15.1),
Microsoft.NET.sdk.Functions (4.1.1)
class Function1.cs:
[FunctionName("HandleMessage")]
public static void Run([ServiceBusTrigger("%ServiceBusQueueName%", Connection = ServiceBusNames.ServiceBusConnectionString)] ServiceBusReceivedMessage queueMessage)
{
var foo = queueMessage;
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"ServiceBusQueueName": "myQueue-myName",
"ServiceBusConnectionString__fullyQualifiedNamespace": "sb-global-dev.servicebus.windows.net",
}
}
It is important to add the logging to the host.json to get the error message:
{
"version": "2.0",
"logging": {
"LogLevel": {
"Default": "Information",
"System": "Warning",
"Microsoft": "Warning",
"AP": "Information",
"Mwp": "Information"
},
"ApplicationInsights": {
"LogLevel": {
"Default": "Information",
"System": "Warning",
"Microsoft": "Warning",
"AP": "Information",
"MWP": "Information"
}
}
}
}
Problem
When we start the function in Visual Studio 2022 via debug mode, we get the following errors in our console output:
Note
Despite the error messages, the ServiceBusTrigger fetches the message from the queue successfully which is confusing.
How can we solve the errors?