Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No parameterless constructor, structuremap, new area

I know the error "No parameterless constructor defined for this object" has been asked about a million times. My situation is different

I have a working app. Many many controllers and one area with lots of controllers. I just added a new area. I added a controller and then a link to that controller. NOW I get the "No parameterless constructor defined for this object" error

I have seen and conquered this problem before but it really only happens like once every 5 months. And everytime I have totally forgotten ( repressed ) the answer.

Please help

Raif

like image 859
Raif Avatar asked Jan 18 '23 02:01

Raif


1 Answers

Ok, so it seems that there are several reasons one might get this error. Not surprisingly none of them have @#$% all to do with not having a parameterless constructor. The two that I'm aware of are

1) if you are using an area and you, say, move a controller from one namespace to the new one and don't update the namespace to reflect the area you will get this error.

2) and this is my situation now, if you are injecting something into the constructor of the controller and the item you are injecting has a problem with it ( there are no instantiations, or it's not registered in your IOC registration or some other runtime error ) you will get this error.

If people can think of others they should list them here because I think there are several more causes for the error. R

like image 59
Raif Avatar answered Jan 28 '23 14:01

Raif