0

Using NServiceBus v7.4.6 plus .NET Core 3.1 and getting the exception

The given key NServiceBus.RecoverabilitySettings was not present in the dictionary.

with the code below when trying to get RecoverabilitySettings in the feature. What could be wrong?

public class MyFeature : Feature
{
    protected override void Setup(FeatureConfigurationContext context)
    {
        var recoverability = context.Settings.Get<RecoverabilitySettings>();
        recoverability.Failed(settings => settings.OnMessageSentToErrorQueue(message =>
        {
            Console.WriteLine(message.MessageId);
            return Task.CompletedTask;
        }));
    }
}

public static class Program
{
    public static async Task Main()
    {
        var configuration = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build();

        var host = Host
            .CreateDefaultBuilder()
            .UseConsoleLifetime()
            .UseNServiceBus(c =>
            {
                var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
                
                var connectionString = configuration.GetConnectionString("AzureServiceBusTransport");
                var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
                transport.ConnectionString(connectionString);
                endpointConfiguration.EnableFeature<MyFeature>();
                
                return endpointConfiguration;
            })
            .Build();

        await host.RunAsync();
    }
}

Update

I try to update the feature from older version 7 of NServiceBus to the latest one where ErrorsNotifications.MessageSentToErrorQueue become obsolete. The old feature code was like

public class MyOldFeature : Feature
{
    protected override void Setup(FeatureConfigurationContext context)
    {
        var notifications = context.Settings.Get<Notifications>();
        notifications.Errors.MessageSentToErrorQueue += this.OnMessageSentToErrorQueue;
    }

    private void OnMessageSentToErrorQueue(object sender, FailedMessage message)
    {
        Console.WriteLine(message.MessageId);
    }
}
Petr Felzmann
  • 1,271
  • 4
  • 19
  • 39

1 Answers1

1

Source: https://docs.particular.net/nservicebus/upgrades/7to8/#error-notification-events

In NServiceBus version 7.2, error notification events for MessageSentToErrorQueue, MessageHasFailedAnImmediateRetryAttempt, and MessageHasBeenSentToDelayedRetries using .NET events were deprecated in favor of Task-based callbacks. In NServiceBus version 8 and above, the event-based notifications will throw an error.

Error notifications can be set with the Task-based callbacks through the recoverability settings:

Settings API is not type-safe and behavior can change across major versions which prevents usage Obsolete in this case on RecoverabilitySettings as that type is still used.

I've created the following issue as I think we could do better in the feedback on this specific breaking change:

https://github.com/Particular/NServiceBus/issues/6080

Ramon Smits
  • 2,482
  • 1
  • 18
  • 20