An error occurred when trying to create a controller of type 'Nop.Admin.Controllers.WarrantyController'. Make sure that the controller has a parameter

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 лет назад
Hi,

I have added a new entity to Nop solution version 3.4, added new classes in Core,Data and services.
Also, I added new controller in admin and web named WarrantyController in order to handle CRUD operations.
Locally on my machine it worked very well. but when i deployed the dlls to the live server. it gives me the error

System.InvalidOperationException: An error occurred when trying to create a controller of type 'Nop.Admin.Controllers.WarrantyController'. Make sure that the controller has a parameterless public constructor. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Nop.Services.Payments.IPaymentService, Nop.Services.Shipping.IShippingService, Nop.Services.Orders.IShoppingCartService, Nop.Services.Directory.ICurrencyService, Nop.Services.Directory.IMeasureService, Nop.Services.Customers.ICustomerService, Nop.Services.Seo.IUrlRecordService, Nop.Core.IWebHelper, Nop.Core.Domain.Directory.CurrencySettings, Nop.Core.Domain.Directory.MeasureSettings, Nop.Services.Helpers.IDateTimeHelper, Nop.Services.Localization.ILanguageService, Nop.Core.IWorkContext, Nop.Core.IStoreContext, Nop.Services.Security.IPermissionService, Nop.Services.Localization.ILocalizationService, Nop.Services.Common.ISearchTermService, Nop.Services.Stores.IStoreService, Nop.Core.Domain.Catalog.CatalogSettings, System.Web.HttpContextBase)' on type 'WarrantyController'. ---> Object reference not set to an instance of an object. (See inner exception for details.) ---> System.NullReferenceException: Object reference not set to an instance of an object. at Nop.Admin.Controllers.WarrantyController..ctor(IPaymentService paymentService, IShippingService shippingService, IShoppingCartService shoppingCartService, ICurrencyService currencyService, IMeasureService measureService, ICustomerService customerService, IUrlRecordService urlRecordService, IWebHelper webHelper, CurrencySettings currencySettings, MeasureSettings measureSettings, IDateTimeHelper dateTimeHelper, ILanguageService languageService, IWorkContext workContext, IStoreContext storeContext, IPermissionService permissionService, ILocalizationService localizationService, ISearchTermService searchTermService, IStoreService storeService, CatalogSettings catalogSettings, HttpContextBase httpContext) at lambda_method(Closure , Object[] ) at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() --- End of inner exception stack trace --- at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate() at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters) at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) 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)


I spent a lot of time on this but no luck!!

Would you please help me.

Thanks
8 лет назад
It sounds like you're injecting an argument into your controller that isn't registered with Autofac.

i.e., if your controller has

public class SomeController
{
public SomeController(ISomeDependency someDependency)
{}
}

ISomeDependency will need to be registered with Autofac, so MVCs dependecyresolver is capable of creating an instance of your controller for you.

For it working on your local development, and not on your live server, you might need to make sure all your assemblies are there.  Visual Studio will follow the assembly dependency chain whereas MSBuild won't.  If your build is being done on a build server, that may have an implication on it.  Beyond that, I wouldn't know why it would work on your development machine, but on your live server.  Anyway you look at it though, all the dependencies can't be resolved by Autofac, so that's what you need to fix.
7 лет назад
Hello, i had the same issue, I know it's to late, but for those interesting, my solution is to include your services into the dependencyRegistrar file (namespace : Nop.Web.Framework), it will be something like this :
builder.RegisterType<WarrantyService>().As<IWarrantyService>().InstancePerLifetimeScope();
after, rebuild your solution and go on.
7 лет назад
Thank you very much David.
This solved my error.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.