[英]Error after updating Entity from Database: No parameterless constructor defined for this object
Has anyone ever seen something like this: 有没有人看过这样的东西:
I've taken over coding an existing solution, which was running along just fine until I added a new table to the database, and then updated the entity from the DB. 我已经接管了现有解决方案的编码,该解决方案一直运行良好,直到我向数据库添加了新表,然后从数据库更新了实体。 Everything seemed fine, until run-time, when all of a sudden I get this error on the home controller: 一切似乎都很好,直到运行时,突然我在家庭控制器上收到了这个错误:
No parameterless constructor defined for this object.
From the stack trace... 从堆栈跟踪...
[InvalidOperationException: An error occurred when trying to create a controller of type 'Response.Controllers.HomeController'. Make sure that the controller has a parameterless public constructor.]
The thing is, the home controller didn't change. 问题是,家庭控制器没有改变。 It never did have a parameterless constructor. 它从来没有没有参数的构造函数。 Further, all the references to it take parameters, so I'm not even sure where/why it thinks it needs a constructor that is parameterless. 此外,对其的所有引用都带有参数,所以我什至不知道它为什么/为什么认为需要无参数的构造函数。
Really confused. 真的很困惑。
Let me know if I need to add something more to help solve this. 让我知道是否需要添加更多帮助解决此问题的方法。 I'm kinda shooting in the dark 'cause I've never seen something like before. 我有点在黑暗中射击,因为我从未见过像以前这样的东西。
EDIT: 编辑:
Here's the constructor: 这是构造函数:
public HomeController([Dependency("ImageUploadPath")] string imageUploadPath,
IPermissions permissions,
IResponseEntitiesFactory responseEntities,
IResponseWebConfiguration responseWebConfiguration,
ILog log)
: base(imageUploadPath, permissions, responseWebConfiguration)
{
_responseEntitiesFactory = responseEntities;
_responseWebConfiguration = responseWebConfiguration;
_log = log;
}
EDIT #2: 编辑#2:
The soluiton is using the Unity DI framework. 解决方案正在使用Unity DI框架。 Here's IUnityContainer ... 这是IUnityContainer ...
public class Bootstrapper
{
public static IUnityContainer BootstrapUnity()
{
IUnityContainer container = new UnityContainer();
container.RegisterInstance(LogManager.GetLogger(typeof(Bootstrapper)));
var log = container.Resolve<ILog>();
container.RegisterType<IResponseQueueConfiguration, ResponseQueueConfiguration>();
var configuration = container.Resolve<IResponseQueueConfiguration>();
container.RegisterType<IMessageDispatcherManager, MessageDispatcherManager>();
container.RegisterType<ResponseTimeHelper, ResponseTimeHelper>(new InjectionConstructor(log)); // hint for unity to default to the parameter less constructor (it tries to default to the IResonseEntities version!)
container.RegisterType<IActivityQueue, MSMQActivityQueue>(new InjectionConstructor(configuration.QueueName));
container.RegisterType<IActivityService, LeadActivityService>();
container.RegisterType<IDispositionDiagnosticService, DispositionDiagnosticService>();
container.RegisterType<IHttpPoxService, HttpPoxService>(new InjectionConstructor(configuration.UrbanScienceDispositionService, log));
container.RegisterType<ICreateWorkflowTasksService, CreateWorkflowTasksService>();
container.RegisterType<INewLeadNotifications, NewLeadNotifications>();
container.RegisterType<IResponseEntities, ResponseEntities>(new PerThreadLifetimeManager());
container.RegisterInstance<IResponseEntitiesFactory>(new SimpleResponseEntitiesFactory(() => new ResponseEntities()));
container.RegisterInstance(container.Resolve<IResponseEntitiesFactory>().Create());
container.RegisterType<ITokenReplacementService, TokenReplacementService>();
container.RegisterType<IMessageProcessor, SendEmailMessageProcessor>("sendemail");
container.RegisterType<IMessageProcessor, SendNewLeadNotificationsMessageProcessor>("sendnewleads");
container.RegisterType<ITokenReplacementService, TokenReplacementService>();
container.RegisterType<ISmtpConfiguration, SmtpConfiguration>();
return container;
}
}
Right now I don't see registrations for IPermissions
, IResponseWebConfiguration
and imageUploadPath
. 现在我看不到IPermissions
, IResponseWebConfiguration
和imageUploadPath
。 There's either another registration file used, or they are not registered. 使用了另一个注册文件,或者未注册。
You can add container.ResolveType<T>
for each of the types I mentioned in the place where your registrations happen after the last registration and check, if any exception is thrown. 您可以为我在上次注册后进行注册的地方提到的每种类型添加container.ResolveType<T>
,并检查是否抛出任何异常。 Also you can manually check container in debug and see all the registrations for your project and determine what is missing. 您也可以在调试中手动检查容器,查看项目的所有注册并确定缺少的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.