Hi everyone,
We’ve just released NServiceBus 8.0.3.
Fixed bugs
-
#6659 Registering
IAsyncDisposable
implementations throws anInvalidOperationException
How to know if you are affected
You are affected if:
- The dependency injection container is managed by NServiceBus
- An implementation of
IAsyncDisposable
is registered byendpointConfiguration.RegisterComponents(…)
as either:-
Single instance:
services => services.AddSingleton<SingletonAsyncDisposable>()
-
Instance per unit of work:
services => services.AddScoped<ScopedAsyncDisposable>()
-
Single instance:
Symptoms
When registering Instance per unit of work implementations of IAsyncDisposable
and resolving them as part of a message handler
public class MyHandler {
public MyHandler(ScopedAsyncDisposable asyncDisposable) { }
}
the message will go through a series of retries and will eventually be moved to the error queue with a similar exception message:
2022-12-23 11:04:23.388 ERROR Moving message '1243a077-6606-4fc7-ae43-af7400a56572' to the error queue 'error' because processing failed due to an exception:
System.InvalidOperationException: 'AsyncDisposable' type only implements IAsyncDisposable. Use DisposeAsync to dispose the container.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.Dispose()
at NServiceBus.MainPipelineExecutor.Invoke(MessageContext messageContext, CancellationToken cancellationToken) in /_/src/NServiceBus.Core/Pipeline/MainPipelineExecutor.cs:line 63
at NServiceBus.LearningTransportMessagePump.ProcessFile(ILearningTransportTransaction transaction, String messageId, CancellationToken messageProcessingCancellationToken) in /_/src/NServiceBus.Core/Transports/Learning/LearningTransportMessagePump.cs:line 340
For Single instance implementations, the InvalidOperationException
will be raised when attempting to stop the endpoint:
2023-01-12 17:10:23.046 INFO Initiating shutdown.
Unhandled exception. System.InvalidOperationException: 'SingletonAsyncDisposable' type only implements IAsyncDisposable. Use DisposeAsync to dispose the container.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.Dispose()
at Microsoft.Extensions.DependencyInjection.ServiceProvider.Dispose()
at NServiceBus.HostingComponent.Stop() in /_/src/NServiceBus.Core/Hosting/HostingComponent.cs:line 100
at NServiceBus.RunningEndpointInstance.Stop(CancellationToken cancellationToken) in /_/src/NServiceBus.Core/Unicast/RunningEndpointInstance.cs:line 66
at Program.Main() in /home/danielmarbach/Projects/docs.particular.net/samples/fullduplex/Core_8/Server/Program.cs:line 29
at Program.<Main>()
When to upgrade
You should upgrade during your next maintenance window if you are planning to use IAsyncDisposable
implementations.
Where to get it
You can install NServiceBus 8.0.3 from NuGet.
With thanks,
The team in Particular
Please read our release policy for more details.