Last Updated: February 25, 2016
·
1.957K
· purekrome

ASP.NET MVC 'No Parameterless Constructor' can be a misleading error

Problem

We've all seen it:

Picture

And we usually waste time trying to figure out why your IoC container isn't working right, etc.

The error is not about an misconfigured IoC. It's because something -during- the dependency injection, failed.

The real error is actually hiding deep down in the stack trace, where the error message is not being displayed.

Solution

IoC hasn't been configured correctly. Check what the controller is trying to inject.

  • Check if you're requiring a database or 3rd party service.
  • Check if you can access the database or 3rd party service.

For myself, I usually have a dependency on a Raven Database. As such, I sometimes forget to start it, when doing local development. So when an IDocumentSession is being injected, it requires an IDocumentStore which fails to instantiate because there is no RavenDb running. Fix: run RavenDb :)