Value cannot be null. Parameter name: serviceType

6 years ago
Hi Guys,

I've started work on a new plugin, but every time I try and install it, I get the following error: Value cannot be null. Parameter name: serviceType.

I've had a look around, but there doesn't seem to be much help on this?

[ArgumentNullException: Value cannot be null.
Parameter name: serviceType]
   Autofac.Util.Enforce.ArgumentNotNull(T value, String name) +95
   Autofac.ResolutionExtensions.TryResolve(IComponentContext context, Type serviceType, Object& instance) +43
   Nop.Core.Infrastructure.DependencyManagement.ContainerManager.TryResolve(Type serviceType, ILifetimeScope scope, Object& instance) +35
   Nop.Core.Plugins.PluginDescriptor.Instance() +66
   Nop.Core.Plugins.PluginDescriptor.Instance() +26
   Nop.Admin.Controllers.<>c__DisplayClass4.<PreparePluginModel>b__0(PluginLocalizedModel locale, Int32 languageId) +59
   Nop.Web.Framework.Controllers.BaseController.AddLocales(ILanguageService languageService, IList`1 locales, Action`2 configure) +161
   Nop.Admin.Controllers.PluginController.PreparePluginModel(PluginDescriptor pluginDescriptor, Boolean prepareLocales, Boolean prepareStores) +494
   Nop.Admin.Controllers.PluginController.EditPopup(String systemName) +219
   lambda_method(Closure , ControllerBase , Object[] ) +104
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +156
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +225
   System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +39
   System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +28
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +29
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +54
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +31
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
6 years ago
It doesn't seem like you've properly registered your service. If you have created custom services, make sure you register it properly. ;)
6 years ago
Hi :)

This is my DependencyRegistrar:

using Autofac;
using Autofac.Core;
using Nop.Core.Configuration;
using Nop.Core.Data;
using Nop.Core.Infrastructure;
using Nop.Core.Infrastructure.DependencyManagement;
using Nop.Data;
using Nop.Plugin.Other.MyTeamsManager.Data;
using Nop.Plugin.Other.MyTeamsManager.Domain;
using Nop.Plugin.Other.MyTeamsManager.Services;
using Nop.Web.Framework.Mvc;

namespace Nop.Plugin.Other.MyTeamsManager
{
    public class DependencyRegistrar : IDependencyRegistrar
    {

        /// <summary>
        /// Register services and interfaces
        /// </summary>
        /// <param name="builder">Container builder</param>
        /// <param name="typeFinder">Type finder</param>
        /// <param name="config">Config</param>
        public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
        {
            builder.RegisterType<MyTeamsManagerService>().As<IMyTeamsManagerService>().InstancePerLifetimeScope();

            //data context
            this.RegisterPluginDataContext<MyTeamsManagerRecordObjectContext>(builder, "nop_object_context_my_teams_manager");

            //override required repository with our custom context
            builder.RegisterType<EfRepository<MyTeamsManagerRecord>>()
                .As<IRepository<MyTeamsManagerRecord>>()
                .WithParameter(ResolvedParameter.ForNamed<IDbContext>("nop_object_context_my_teams_manager"))
                .InstancePerLifetimeScope();
        }

        public int Order
        {
            get { return 1; }
        }

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

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

            return new MyTeamsManagerRecordObjectContext(dataConnectionStrings);
        }

    }
}
6 years ago
p.s. I'm pulling my hair out!! ;)
6 years ago
Never mind, managed to get it sorted :)

I'd completely forgot to add a simple MyTeamsManagerPlugin.cs file with Install() etc ;)