Throw an exception in a class which is instantiated via DI injection.
result:
Unhandled exception. System.InvalidOperationException: Can only stop a started instance.
at Google.Api.Gax.GaxPreconditions.CheckState(Boolean condition, String message)
at Google.Cloud.PubSub.V1.SubscriberClientImpl.StopAsync(CancellationToken hardStopToken)
at Google.Cloud.PubSub.V1.SubscriberClient.StopAsync(TimeSpan timeout)
at Google.Cloud.PubSub.V1.SubscriberClientImpl.DisposeAsync()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.DisposeAsync()
--- End of stack trace from previous location ---
at Microsoft.Extensions.Hosting.Internal.Host.g__DisposeAsync|21_0(Object o)
at Microsoft.Extensions.Hosting.Internal.Host.DisposeAsync()
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at WebApplication.Program.Main(String[] args)
Expected result:
DisposeAsync does not throw an exception if it hasn't been started yet. The constructor exception will be caught in DI container and logged.
Environment details
Steps to reproduce
result:
Unhandled exception. System.InvalidOperationException: Can only stop a started instance. at Google.Api.Gax.GaxPreconditions.CheckState(Boolean condition, String message) at Google.Cloud.PubSub.V1.SubscriberClientImpl.StopAsync(CancellationToken hardStopToken) at Google.Cloud.PubSub.V1.SubscriberClient.StopAsync(TimeSpan timeout) at Google.Cloud.PubSub.V1.SubscriberClientImpl.DisposeAsync() at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.DisposeAsync() --- End of stack trace from previous location --- at Microsoft.Extensions.Hosting.Internal.Host.g__DisposeAsync|21_0(Object o)
at Microsoft.Extensions.Hosting.Internal.Host.DisposeAsync()
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at WebApplication.Program.Main(String[] args)
Expected result: DisposeAsync does not throw an exception if it hasn't been started yet. The constructor exception will be caught in DI container and logged.