Skip to content
This repository was archived by the owner on Nov 2, 2018. It is now read-only.

AddSingleton is swallowing exceptions silently #401

Closed
colemickens opened this issue Apr 13, 2016 · 7 comments
Closed

AddSingleton is swallowing exceptions silently #401

colemickens opened this issue Apr 13, 2016 · 7 comments

Comments

@colemickens
Copy link

services.AddSingleton<IDatabase>((IServiceCollection) => configureRedis());

configureRedis() is throwing an exception. I know because I catch it, print the exception and then rethrow it. It seems that AddSingleton or something down the stack is swallowing the exception. As a user, I didn't know until I was informed that Could not resolve a service of type 'StackExchange.Redis.IDatabase' for the parameter.....

Not sure if this is standard for DI or a bug or something else?

@nil4
Copy link

nil4 commented Apr 14, 2016

Could be related to aspnet/Hosting#695

@pranavkm
Copy link
Contributor

Dup of aspnet/Tooling#363.

@colemickens
Copy link
Author

@pranavkm Can you give more details? That bug was labeled "fixed" nearly two months ago yet I'm experiencing this will the latest dotnet builds.

@davidfowl
Copy link
Member

@colemickens repro?

colemickens added a commit to colemickens/cli-samples that referenced this issue Apr 18, 2016
@colemickens
Copy link
Author

This commit shows what I'm seeing at least, on top of the cli-samples repo:

colemickens/cli-samples@cd71527

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:06.1246725


Unhandled Exception: System.Exception: Could not resolve a service of type 'HelloMvcApi.IFoo' for the parameter 'foo' of method 'Configure' on type 'HelloMvcApi.Startup'.
   at Microsoft.AspNetCore.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at HelloMvcApi.Program.Main(String[] args)

So, it gets to ConfigureServices and complains there's no IFoo, but it didn't complain about the uncaught exception in makeFoo. But maybe I'm misunderstanding the expected behavior...

@colemickens
Copy link
Author

David got me sorted out in Jabbr. I'm still seeing this because I'm using the ci release nuget feed. Thanks all.

@colemickens
Copy link
Author

AFAICT this is still happening...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants