You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
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.
interfaceITestService{}// There are many of these classes.classTestService:ITestService{TestService(){}}
...vartestServices= 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.
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.
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.
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
The text was updated successfully, but these errors were encountered: