Skip to content

The thrown exception's message is completely useless... #44895

@ghost

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When an ASP.NET/gRPC application is first starting, it configures its http or https endpoints. If something is not configured correctly the application throws an error which is completely useless! The offending error is:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'IServiceProvider'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException()
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdownAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.WaitForShutdown(IHost host)
   at Program.<Main>$(String[] args) in D:\Development\Moby\Dev\MobyFileTransferServices\MobyFileTransferServices\Program.cs:line 206.

I have found that if any of the following occurs, this exception is thrown:

  1. If the port is incorrect
  2. If the TLS certificate is not found
  3. If the TLS certificate's password is not correct
  4. and there are others that I will add to this list when I can remember what they are

The internal code (either ASP.NET or gRPC - I am posting this in both forums) knows why it is throwing the exception so why not just say why the exception is being thrown! The Object name: 'IServiceProvider' message is a true red herring and completely useless. As I have come to have more experience on getting this to work, I grow more agitated in the lack of quality of that message. Look, getting SSL to work is hard enough to begin with. Help your developer community by throwing a better, more specific error!!!

For completeness' sage, I am including my Kestrel configuration.
appsettings:

	"Kestrel": {
		"EndpointDefaults": {
			"Protocols": "Http2",
			"SslProtocols": [ "Tls12" ]
		},
		"Endpoints": {
			"Https1": {
				"Certificate": {
					"Password": "123456",
					"Path": "localhost.pfx"
				},
				"Url": "https://*:30054"
			}
		}
	}

program.cs:

	// Add services to the container.
	_ = builder.Services.AddGrpc (grpcServiceOptions => {
		logger?.Debug ("Configuring presence intercepter...");
		grpcServiceOptions.Interceptors.Add<PresenceInterceptor> ();
		_ = grpcServiceOptions.EnableDetailedErrors = true;
	});

There is nothing special about this configuration. It's very simple. Please provide better messages as to why this initialization fails!!!

Regards,
Steve Miller

Expected Behavior

Provide an explanatory message that describes the ACTUAL reason the exception is being thrown!!!

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7.0.100-rc.2.22477.23 but I'm actually using .NET 6

Anything else?

NOTE: I have downloaded both the gRPC and ASP.NET repositories and can't even find the string "Cannot access a disposed object" in the code... I have no idea where this message is being thrown from...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions