I am using StructureMap 3 with MVC 5. The problem is that whenever an exception happens in the controller constructor I get a misleading StructureMap error instead of the actual error.
For example I have the following controller:
public class CustomerService : ICustomerService
{
private readonly DataContext db;
public CustomerService(DataContext db)
{
this.db = db;
// Some code that causes exception
throw new NullReferenceException();
}
}
Whenever I try to access an action from that controller I get the following StructureMap error:
No parameterless constructor defined for this object.
[MissingMethodException: No parameterless constructor defined for this object.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +66
System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
What can I do to see the actual exception when there is a problem in a controller constructor?