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

ActivatorUtilities exceptions lack context #386

Closed
wesleyolis opened this issue Mar 17, 2016 · 3 comments
Closed

ActivatorUtilities exceptions lack context #386

wesleyolis opened this issue Mar 17, 2016 · 3 comments
Assignees
Milestone

Comments

@wesleyolis
Copy link

Background

Spent about a day of work attempting to resolve exception thrown from the activator.
We have many services from different projects that have been registered and upon integration of all of them, attempting to resolve one the services, the activator failed and threw an error.
This error, of the form "No parameter-less constructor defined", provided absolute no context
of which service failed to resolve. We had to eventually do a process of elimination and manually go register each of the services and binary search to find out which service type that was registered was failing to resolve.

issue

The problem is caused by a private constructor and results in and exception
that may not lead you directly to the source.

Reproduce

Define a class with no public constructors, that inherits from an interface,
then register the service and try resolved the interface.

interface ITestService
{
}
// There are many of these classes.
class TestService :ITestService
{
   TestService()
   {
   }
}

...
var testServices = Container.GetServices<ITestService>();
// Throws exception 'No parameter-less constructor defined'

Suggestions

Provide context to any exceptions throw in the activator,
ideally one would include information about the type being activated
to help track down the culprit(s).

Please let know if you have any future questions or if I can help out in anyway.

/cc @spartan563

@Eilon Eilon added this to the 1.0.0 milestone Mar 17, 2016
@Eilon Eilon modified the milestones: 1.0.1, 1.0.0 May 17, 2016
@Eilon Eilon modified the milestones: 1.1.0, 1.1.0-preview1 Oct 6, 2016
@Eilon Eilon modified the milestones: 1.2.0, 1.1.0 Nov 2, 2016
@Eilon
Copy link
Member

Eilon commented Mar 3, 2017

Seems like the error message should at least be something like The type '{0}' does not have a public parameter-less constructor defined..

If we're currently calling Activator.CreateInstance then we'll need to add some code to check this ahead of time. We'd need to make sure that the perf doesn't take a hit if this is an extra check.

@muratg
Copy link

muratg commented Apr 25, 2017

@Eilon punting this out of preview1. Please bring back if you want this in.

@muratg muratg modified the milestones: 2.0.0-preview3, 2.0.0-preview2 May 30, 2017
@Eilon Eilon modified the milestones: 2.0.0, 2.0.0-preview3 Jun 8, 2017
@pakrym
Copy link
Contributor

pakrym commented Jun 21, 2017

Duplicate and fixed. #310

@pakrym pakrym closed this as completed Jun 21, 2017
@pakrym pakrym added 3 - Done and removed 1 - Ready labels Jun 21, 2017
This issue was closed.
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