debug help: "No parameterless constructor defined for this object"

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 yıl önce
I am trying to add custom code into the pre-beta nopcommerce 2.0 to get a better handle on how the new framework will be built up. So I apologize for jumping the gun and my nubishness as well but i'm really stuck here.

What I am trying to do is copy the topics module since I'm going to need a variety of topics for my site. For example, instead of ~/t/aboutus, I want it to be ~/articles/aboutus. I did this by running through and copying over every model, view, controller, IOC service class, and references to topics to a new class called articles. The corresponding table exists in the database and the sample data matches that of the topics table.

Now the only reason I'm doing it this way is to learn, since I could probably just add a type field in the topics that distinguishes the type of object (topic/article) and route from there. I just figure this is a good way to see how nopcommerce on MVC ticks. If there's a better way/tutorial out there, please direct me!

I've been doing a lot of research to figure out how to debug and test this issue, but I don't have the answer yet. I've done the MVC3 tutorials on MSDN, read articles on IOC like this one http://bradwilson.typepad.com/blog/2010/10/service-location-pt5-idependencyresolver.html, googled it, watched a MVC tutorial, but I still can't resolve my issue.

I feel like I'm so close to getting this but I need help. It says I'm missing a parameterless constructor. The constructor takes in the service and the work context. The service class takes in an IRepository of type Article which uses the BaseEntity to move the objects in and out of the database. All of that makes sense but I don't know how it's supposed to get a parameterless constructor when I don't see any parameterless constructors in the other classes. Any guidance is greatly appreciated!

The exact error is as follows when I try to load ~/article/aboutus:
No parameterless constructor defined for this object.
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.

and the relevant stack trace:
[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) +98
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +67

[InvalidOperationException: An error occurred when trying to create a controller of type 'Nop.Web.Controllers.ArticleController'. Make sure that the controller has a parameterless public constructor.]
   System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +182
   System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
...and so on

Thanks!
12 yıl önce
It seems that some of services that you pass your controller is not registered in Autofac. Please post the code of the controller that you're requesting
12 yıl önce
Oh! Thank you for that! I registered it in the Nop.Web.Framework.DependencyRegistrar and it works now! :D
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.