简体   繁体   English

没有无参数构造函数,结构图,新区域

[英]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. 我之前已经看到并克服了这个问题,但它实际上只发生在每5个月一次。 And everytime I have totally forgotten ( repressed ) the answer. 每次我完全忘记(压抑)答案。

Please help 请帮忙

Raif RAIF

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. 1)如果您正在使用某个区域,并且您将控制器从一个名称空间移动到新名称空间,并且不更新名称空间以反映您将收到此错误的区域。

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. 2)这是我现在的情况,如果你在控制器的构造函数中注入一些东西,你注入的项目有问题(没有实例化,或者它没有在你的IOC注册或其他运行时错误中注册) )你会得到这个错误。

If people can think of others they should list them here because I think there are several more causes for the error. 如果人们可以想到别人,他们应该在这里列出它们,因为我认为还有几个原因导致错误。 R [R

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. 我最近在使用MVC Contrib项目的MVC Portable Area时遇到了同样的问题。 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: 我发现在IOC注册期间扫描组件时,必须还包括便携式区域所具有的任何dll依赖性,这类似于以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM