Search code examples
azure-functions.net-8.0dotnet-isolated

Issue during Upgrade of Azure functions to .NET 8 and isolated workers


Hi I upgrading my workers to dotnet 8 and isolated worker. I have removed the Microsoft.Azure.Webjobs.Extensions.ServiceBus dependency as suggested in document https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8#programcs-file.

But now I am getting error in Program.cs file for line:

services.Configure<ServiceBusOptions>(options =>
{
    options.AutoCompleteMessages = false;
});

with ServiceBusOptions that it cannot be found. What can I do here?

here is my hostbuilder function,

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
        services.Configure<ServiceBusOptions>(options =>
        {
            options.AutoCompleteMessages = false;
        });
    })
    .Build();

host.Run();

I am not sure what to do, since I am new to .NET and Azure, any help would be appreciated.


Solution

  • Thanks for the article @Andrew B.

    I got the same error when I tried to implement the same in my environment.

    The type or namespace name 'ServiceBusOptions' could not be found (are you missing a using directive or an assembly reference?).

    Refer the MSDOC for the example code.

    To set AutoCompleteMessages= false, add the attribute in the function code as shown below:

    [Function(nameof(Function1))]
    public async Task Run(
        [ServiceBusTrigger("myqueue", Connection = "demo", AutoCompleteMessages = false)]
        ServiceBusReceivedMessage message,
        ServiceBusMessageActions messageActions)
    {
        _logger.LogInformation("Message ID: {id}", message.MessageId);
        _logger.LogInformation("Message Body: {body}", message.Body);
        _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);
    
        // Complete the message
        await messageActions.CompleteMessageAsync(message);
    }
    

    Program.cs:

    var host = new HostBuilder()
        .ConfigureFunctionsWebApplication()
        .ConfigureServices(services =>
        {
            services.AddApplicationInsightsTelemetryWorkerService();
            services.ConfigureFunctionsApplicationInsights();
        })
        .Build();
    
    host.Run();
    

    Sending message:

    enter image description here

    Console Response:

    enter image description here