Usuario
Error al ejecutar aplicación MVC

Pregunta
-
Por favor su apoyoEstimados por favor su apoyo, al ejecutar el proyecto me muestra el siguiente mensaje de error. Alguien podría orientarme para corregir el problema presentado.
No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. [MissingMethodException: No parameterless constructor defined for this object.] System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113 System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232 System.Activator.CreateInstance(Type type, Boolean nonPublic) +83 System.Activator.CreateInstance(Type type) +6 System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +110 [InvalidOperationException: An error occurred when trying to create a controller of type 'xxxx.yyyy.Web.Mvc.Controllers.LoginController'. Make sure that the controller has a parameterless public constructor.] System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +247 System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +438 System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +257 MvcSiteMapProvider.DI.ControllerFactoryDecorator.CreateController(RequestContext requestContext, String controllerName) +270 System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +328 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +157 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Todas las respuestas
-
hola
El error menciona que no tienen ningun constructor sin parametros
usas algun framework de IoC ? como ser Unity, Ninject, etc
public class LoginController : Controller{ public LoginController(){ } //resto codigo }
debes asegurar que haya un constructor sin parametros
saludos
Leandro Tuttini
Blog
MVP Profile
Buenos Aires
Argentina -
-
Se te está quejando de que userValidationService no está definido. Presumiblemente, esa variable es una dependencia que debiste inyectar por mediación de Ninject, pero al añadir el constructor predeterminado se está utilizando éste y en consecuencia la dependencia se queda sin inyectar.
En resumidas cuentas, estás usando mal tu infraestructura de IoC. Si usas constructores sin parámetros, tienes que generar en ellos las dependencias. Y si los usas con parámetros, tienes que configurar la infraestructura para que inyecte el correspondiente parámetro al instanciar el controlador.
- Propuesto como respuesta Sergio ParraModerator domingo, 8 de mayo de 2016 16:22
-
hola
Si utilizas Ninject puede que no hayas definido en el mappingo no estas definiendo en el constructor el "userValidatorService"
Deberias validar que este mapeando el userValidatorService en ninject, indicando la interfaz con cual clase concreta debe resolver
Nota: si usas ninject entonces quita el constructor sin parametros ya que debe resolverse las dependencias cuando ingresa al controller, esta claro que eso es lo que hay que resolver
saludos
Leandro Tuttini
Blog
MVP Profile
Buenos Aires
Argentina- Propuesto como respuesta Sergio ParraModerator domingo, 8 de mayo de 2016 16:22