again "No parameterless constructor defined for this object"

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Hi. I've writing two plugins for NopCommerce 2.50.

One is written successfully and working well.
With the second one is problem. I just can't understand, there is totaly the same code (excluding classname) as in the first one.

here is stack:

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.  

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.Plugin.ProductsImport.VendorCategories.Controllers.ProductsImportVendorCategoriesController'. 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
   System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
   System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory) +218
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970356
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184



and here is dependency injection


public class VendorCategoryDependencyRegistrar : IDependencyRegistrar
    {
        private const string CONTEXT_NAME = "nop_object_context_vendorcategory";

        public void Register(ContainerBuilder builder, ITypeFinder typeFinder)
        {
            var dataSettingsManager = new DataSettingsManager();
            DataSettings dataSettings = dataSettingsManager.LoadSettings();

            builder.Register<IDbContext>(c => RegisterIDbContext(c, dataSettings)).Named<IDbContext>(CONTEXT_NAME).InstancePerHttpRequest();
            builder.Register(c => RegisterIDbContext(c, dataSettings)).InstancePerHttpRequest();

            builder.RegisterType<VendorCategoryService>().As<IVendorCategoryService>();

            builder.RegisterType<EfRepository<VendorCategory>>().As<IRepository<VendorCategory>>().WithParameter(ResolvedParameter.ForNamed<IDbContext>(CONTEXT_NAME)).InstancePerHttpRequest();
        }

        public int Order
        {
            get { return 0; }
        }

        /// <summary>
        /// Registers the I db context.
        /// </summary>
        /// <param name="componentContext">The component context.</param>
        /// <param name="dataSettings">The data settings.</param>
        /// <returns></returns>
        private VendorCategoryObjectContext RegisterIDbContext(IComponentContext componentContext, DataSettings dataSettings)
        {
            string dataConnectionStrings;

            if (dataSettings != null && dataSettings.IsValid())
            {
                dataConnectionStrings = dataSettings.DataConnectionString;
            }
            else
            {
                dataConnectionStrings = componentContext.Resolve<DataSettings>().DataConnectionString;
            }

            return new VendorCategoryObjectContext(dataConnectionStrings);
        }
    }


where it could be wrong?

Thanks a lot!
11 years ago
Please post your ProductsImportVendorCategoriesController class here
11 years ago
[AdminAuthorize]
    public class ProductsImportVendorCategoriesController: Controller
    {
        private IVendorCategoryService _vendorCategoryServices;

        public ProductsImportVendorCategoriesController(IVendorCategoryService vendorCategoryService)
        {
            this._vendorCategoryServices = vendorCategoryService;
        }
        
        public ActionResult Index()
        {
            List<VendorCategoryModel> vendorCategoriesList = (from ven in _vendorCategoryServices.GetVendorCategories()
                              select new VendorCategoryModel()
                              {
                                  VendorCategoryId = ven.Id,
                                  VendorCategoryName = ven.VendorCategoryName
                              }).ToList();
            GridModel<VendorCategoryModel> gridModel = new GridModel<VendorCategoryModel>(vendorCategoriesList);
            return View("Nop.Plugin.ProductsImport.VendorCategories.Views.ProductsImportVendorCategories.Index", gridModel);
        }

        [GridAction(EnableCustomBinding = true)]
        public ActionResult VendorCategoryDelete(int id, GridCommand command)
        {
            var vendorCategory = _vendorCategoryServices.GetVendorCategory(id);
            _vendorCategoryServices.DeleteVendorCategory(vendorCategory);

            return Index();
        }

        [GridAction(EnableCustomBinding = true)]
        public ActionResult VendorCategoryUpdate(int id,VendorCategoryModel model, GridCommand command)
        {
            var vendorCategory = _vendorCategoryServices.GetVendorCategory(id);
            vendorCategory.VendorCategoryName = model.VendorCategoryName;
            _vendorCategoryServices.UpdateVendorCategory(vendorCategory);

            return Index();
        }

        [GridAction(EnableCustomBinding = true)]
        public ActionResult VendorCategoryInsert(VendorCategoryModel model, GridCommand command)
        {
            var vendorCategory = new Domain.VendorCategory();
            vendorCategory.VendorCategoryName = model.VendorCategoryName;
            _vendorCategoryServices.InsertVendorCategory(vendorCategory);

            return Index();
        }
11 years ago
this is identical with plugin that is working. there is no difference between them, just classes names Vendor and VendorCategory.
11 years ago
This one looks fine. Could you also post your VendorCategoryService class (or maybe the entire plugin source code)?
11 years ago
Just re-wrote plugin. Was easier and quicker. Now is working fine.

Thanks!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.