繁体   English   中英

从数据库更新实体后发生错误:未为此对象定义无参数构造函数

[英]Error after updating Entity from Database: No parameterless constructor defined for this object

有没有人看过这样的东西:

我已经接管了现有解决方案的编码,该解决方案一直运行良好,直到我向数据库添加了新表,然后从数据库更新了实体。 一切似乎都很好,直到运行时,突然我在家庭控制器上收到了这个错误:

No parameterless constructor defined for this object.

从堆栈跟踪...

[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.]

问题是,家庭控制器没有改变。 它从来没有没有参数的构造函数。 此外,对其的所有引用都带有参数,所以我什至不知道它为什么/为什么认为需要无参数的构造函数。

真的很困惑。

让我知道是否需要添加更多帮助解决此问题的方法。 我有点在黑暗中射击,因为我从未见过像以前这样的东西。

编辑:

这是构造函数:

        public HomeController([Dependency("ImageUploadPath")] string imageUploadPath, 
            IPermissions permissions, 
            IResponseEntitiesFactory responseEntities, 
            IResponseWebConfiguration responseWebConfiguration,
            ILog log)
            : base(imageUploadPath, permissions, responseWebConfiguration)
        {
            _responseEntitiesFactory = responseEntities;
            _responseWebConfiguration = responseWebConfiguration;
            _log = log;
        }

编辑#2:

解决方案正在使用Unity DI框架。 这是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;
    }
}

现在我看不到IPermissionsIResponseWebConfigurationimageUploadPath 使用了另一个注册文件,或者未注册。

您可以为我在上次注册后进行注册的地方提到的每种类型添加container.ResolveType<T> ,并检查是否抛出任何异常。 您也可以在调试中手动检查容器,查看项目的所有注册并确定缺少的内容。

暂无
暂无

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

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