Raif
Raif

Reputation: 9249

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

Upvotes: 4

Views: 3683

Answers (2)

akousmata
akousmata

Reputation: 1043

While I realize this doesn't truly answer your question, your answer helped me in my troubleshooting endeavors.

I just recently came across this same issue while using MVC Portable Areas from the MVC Contrib project. I found that any dll dependancies the portable areas had must also be included when scanning for assemblies during IOC registration, something along the lines of this:

ObjectFactory.Initialize(x => x.Scan(y =>
    {
        y.Assembly("PortableAreaAssemblyName");
    }));
ObjectFactory.Configure(x =>
    {
        x.For<IClassInterfaceUsedByControllerConstructor>().Use<IntendedClassInstance>();
    });

Upvotes: 0

Raif
Raif

Reputation: 9249

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

Upvotes: 9

Related Questions