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

Improve error message for "No parameterless constructor defined for this object" #310

Closed
toddlucas opened this issue Oct 24, 2015 · 5 comments
Assignees
Milestone

Comments

@toddlucas
Copy link

This error message will manifest if a constructor is private, but is a dependency of another class. The following exception is thrown in beta7:

System.MissingMethodException: No parameterless constructor defined for this object.

It would be great if the message would identify the type with the missing constructor. Otherwise, one must resort to binary search debugging (commenting out various DI inputs) or similar efforts.

@mafshin
Copy link

mafshin commented Jul 9, 2016

@pranavkm Why should I get this incomplete error message while using ASP.NET Core 1.0 ?

StackTrace:

icrosoft.AspNetCore.Hosting.Internal.WebHost: Information: Request finished in 64.5025ms 200 
Microsoft.AspNetCore.Server.Kestrel: Error: Connection id "0HKT7NOIT25RI": An unhandled exception was thrown by the application.

System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.AspNetCore.Routing.DefaultInlineConstraintResolver.CreateConstraint(Type constraintType, String argumentString)
   at Microsoft.AspNetCore.Routing.DefaultInlineConstraintResolver.ResolveConstraint(String inlineConstraint)
   at Microsoft.AspNetCore.Routing.RouteConstraintBuilder.AddResolvedConstraint(String key, String constraintText)
   at Microsoft.AspNetCore.Routing.Tree.TreeRouteBuilder.MapOutbound(IRouter handler, RouteTemplate routeTemplate, RouteValueDictionary requiredLinkValues, String routeName, Int32 order)
   at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.AddEntries(TreeRouteBuilder builder, ActionDescriptorCollection actions)
   at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.GetTreeRouter()
   at Microsoft.AspNetCore.Mvc.Internal.AttributeRoute.RouteAsync(RouteContext context)
   at Microsoft.AspNetCore.Routing.RouteCollection.<RouteAsync>d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.<Invoke>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
Microsoft.AspNetCore.Hosting.Internal.WebHost: Information: Request finished in 347.2296ms 200 

project.json

  "dependencies": {
    "Autofac.Extensions.DependencyInjection": "4.0.0-rc3-280",
    "AutoMapper": "5.0.0",
    "log4net": "2.0.5",    
    "Microsoft.AspNetCore.Identity": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0",
    "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Owin.Host.SystemWeb": "3.0.1",
    "BrockAllen.MembershipReboot": "8.4.0",
    "Autofac": "4.0.0-rc3-286",
    "BrockAllen.MembershipReboot.Ef": "8.0.0",    
  },

@pranavkm
Copy link
Contributor

@mafshin I don't see DI anywhere in the stack trace here.

@mafshin
Copy link

mafshin commented Jul 12, 2016

As I said here(aspnet/Mvc#4991) the misleading
error message brought me here.
On 11 Jul 2016 21:01, "Pranav K" notifications@github.com wrote:

@mafshin https://github.com/mafshin I don't see DI anywhere in the
stack trace here.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#310 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AEs50ElMdO7xQSpmbNwMtwBJiTsdshXzks5qUm_XgaJpZM4GVGJm
.

@mohamedmansour
Copy link

@pranavkm The error would be nice to tell me which service in the DI is causing this issue, instead of me hunting it down.

@pranavkm
Copy link
Contributor

@mohamedmansour do you have a stack trace for the error? We fixed the issue in the 1.0.0-rc2 milestone, so you shouldn't see this message coming from DI anymore.

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