0
votes

I am working on a ASP.NET MVC 5 application. I have used Unit for DI. Application is working fine when I run it locally or even when I deploy it on IIS locally. But I was trying to move it to a Windows 2007(or 2008) server and it ends up in error stating that "Controller doesn't have parameterless constructor". I am guessing that this must be due to DI injection failing, but I couldn't find any clue in any logs. Following is the detailed error that is being returned:

Make sure that the controller has a parameterless public constructor. ---> System.MissingMethodException: No parameterless constructor defined for this object. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) --- End of inner exception stack trace --- at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Can someone help?

1
Show your controller code and if you have, controller factoryBacks
Apparently, the default factory is used rather than unity factory.Wiktor Zychla
I derived my controller from "Controller" class. But as I said it works fine if I deploy in in my local IIS, the issue is only when I push it to the server. public class MyController : ControllerRam V
How is unity used so that it works locally and doesn't remotely? Can you show your unity code?Wiktor Zychla
I don't have the access to code right now but I can add the unity code as soon as I have the access (it is in a different PC). But I used FusionLogs and found that there were two assembly load errors one was with Oracle data client (which is missing on that server) another is Microsoft.Practices.Unity.resources. I am in the process of getting the Oracle data client and haven't done anything for Unity.resources yet. I am not even using Unity.resources in my application so not sure from where it is picking it up. If its a dependency then it should have given error in my local machine as well.Ram V

1 Answers

0
votes

Finally, installed Oracle Data Client worked. Not sure why it was complaining about Microsoft.Practices.Unity.Resources in fusion logs, but after installing Oracle Data Client it worked.