I was trying to create an Azure Function with an NServicebus trigger, but kept receiving the error in the title on build. Since it took me some time figure out what was actually causing it, here what I discovered.
So I started of creating a new Azure Function with Service Bus trigger in Visual Studio 2022. To stay up to date, one of the first things I did was opening up the Manage NuGet Packages window and started updating the packages listed in Updates tab. In hindsight, this is where the issues started.
I added a Startup file and decorated the namespace with the two attributes:
[assembly: FunctionsStartup(typeof(Startup))]
[assembly: NServiceBusTriggerFunction(Constants.EndpointName)]
And started configuring NServicebus, based on their docs with the most basic version:
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.UseNServiceBus(() => new ServiceBusTriggeredEndpointConfiguration("TestEndpoint"));
}
}
While haven written a lot of other code, I tried a build and kept getting a handful of errors like below:
NServiceBus.AzureFunctions.SourceGenerator/NServiceBus.AzureFunctions.SourceGenerator.TriggerFunctionGenerator2/NServiceBus__FunctionEndpointTrigger.cs(2,23): Error CS0234: The type or namespace name 'ServiceBus' does not exist in the namespace 'Microsoft.Azure' (are you missing an assembly reference?)
I took me some time to figure out, this was caused by a package upgrade I perfomered:
I updated “Microsoft.Azure.WebJobs.Extensions.ServiceBus” to the latest stable version at the time of writing: 5.2.0. However this caused NServicebus not to function properly. To make it work, use version: 4.3.0. So in your project file you should see a reference as below (using NServiceBus.AzureFunctions.InProcess.ServiceBus (2.1.0)):
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />