0

I'm using NserviceBus with the Azure Function project ( NServiceBus.AzureFunctions.InProcess.ServiceBus). Application is using azure service bus as the transport and it is configured in function startup by using the below code

 var transport = configuration.AdvancedConfiguration.UseTransport<AzureServiceBusTransport>();
            transport.ConnectionString(@"AzureWebJobsServiceBus".GetConfig());

Everything was working fine in .NET Core 3.1 and Azure function version 3.0. Recently I upgrade the project to .NET 6 and Function version to 4.0. After the upgrade, functionEndpoint.Process is throwing a null reference exception.

If the UseTransport code is commented out in function startup, no exception is thrown and the messages are getting processed successfully. But I need to have the UseTransport in the startup configuration for the NServiceBus to set up the transport topology automatically. Please help me to resolve this issue.

rinesh
  • 493
  • 1
  • 8
  • 26

2 Answers2

1

If you are using the NServiceBus.AzureFunctions.InProcess.ServiceBus package then you should not be calling UseTransport<>().

The library does this for you but it also contains some additional code to prevent the message receiver part of the transport from starting. Instead, the endpoint simply sits and waits for one of the Azure Function Trigger methods to call one of the endpoints Process methods.

If you call UseTransport<>() yourself, then the standard message receiver is started and when the Azure Function Trigger calls a Process method, the interception code has not been properly configured. That is why you see a Null Reference Exception.

You should not rely on the NServiceBus endpoint to create the topology in the transport. The endpoint is only created when the first Azure function is triggered. Typically this happens when a message arrives but that can't happen before the topology is set up. There is a command-line tool that is provided to help provision a new Azure Service Bus environment for use with NServiceBus.

Mike Minutillo
  • 54,079
  • 14
  • 47
  • 41
0

As you are using the stable versions for your application like:

enter image description here

I would suggest to change the syntax and try based on connection string use cases:

To use Azure Service Bus as the underlying transport: Method 1:

If your connection string variable AzureServiceBusConnectionString is present in the web config file, then try calling the connection string using the below code:

var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
var connectionString = context.Configuration.GetConnectionString("AzureServiceBusConnectionString"); 
transport.ConnectionString(connectionString);

Method 2: Giving the connection string directly

var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>(); transport.ConnectionString("Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]");

For more detailed information to fetch the connection string from web config using configuration manager to context in the application (method 1), please check this Microsoft documentation.