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

Internal constructor causes vague exception message #182

Closed
ryan-codingintrigue opened this issue Mar 1, 2015 · 3 comments
Closed

Internal constructor causes vague exception message #182

ryan-codingintrigue opened this issue Mar 1, 2015 · 3 comments
Assignees
Milestone

Comments

@ryan-codingintrigue
Copy link

I've just spent a decent amount of time trying to debug the following exception:

System.ArgumentNullException
Object cannot be null.
Parameter name: source

at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture(Exception
source) at
Microsoft.Framework.DependencyInjection.ServiceLookup.Service.CreateInstanceCallSite.Invoke(ServiceProvider
provider) at
Microsoft.Framework.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider
provider) at
Microsoft.Framework.DependencyInjection.ServiceLookup.Service.ConstructorCallSite.Invoke(ServiceProvider
provider) at
Microsoft.Framework.DependencyInjection.ServiceProvider.TransientCallSite.Invoke(ServiceProvider
provider) at
Microsoft.Framework.DependencyInjection.ServiceProvider.<>c__DisplayClass8_0.b__0(ServiceProvider
provider) at
Microsoft.Framework.DependencyInjection.ServiceProvider.GetService(Type
serviceType) at
Microsoft.Framework.DependencyInjection.TypeActivator.ConstructorMatcher.CreateInstance(IServiceProvider
_services) at Microsoft.Framework.DependencyInjection.TypeActivator.CreateInstance(IServiceProvider
services, Type instanceType, Object[] parameters) at
Microsoft.AspNet.Mvc.DefaultControllerFactory.CreateController(ActionContext
actionContext)

Turns out all that was wrong was the constructor for my concrete implementation was marked as internal. Changing it to public works fine. I understand why, but the exception message was not helpful in trying to diagnose the issue.

@davidfowl
Copy link
Member

Do you want to send a PR for this?

@ryan-codingintrigue
Copy link
Author

I can certainly give it a go

@mdekrey
Copy link

mdekrey commented May 17, 2015

This exception also crops up when there's multiple public constructors on the class being instantiated.

I believe this gives a better error message with this commit by @davidfowl - adding the conditional when (ex.InnerException != null) should do it. Unfortunately, I'm not running against the daily builds so I can't confirm.

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

5 participants