Problem with plugins during NopCommerce development

0

I'm going to do some development on NopCommerce 4.0. I have imported NopCommerce 4.0 source codes into VS 2019. When I try to run my project, all of plugins generate exceptions like this inside Resolve method NopEngine.cs:

public object Resolve(Type type)
{
    return GetServiceProvider().GetRequiredService(type);
}

E.g. one of the exceptions is:

'Nop.Plugin.Payments.CheckMoneyOrder.CheckMoneyOrderPaymentProcessor' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

And here is complete exception details:

Autofac.Core.Registration.ComponentNotRegisteredException
HResult=0x80131500 Message=The requested service 'Nop.Plugin.Payments.CheckMoneyOrder.CheckMoneyOrderPaymentProcessor' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency. Source=Autofac StackTrace: at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(Type serviceType) at Nop.Core.Infrastructure.NopEngine.Resolve(Type type) in V:\nopCommerce_4.00_Source\Libraries\Nop.Core\Infrastructure\NopEngine.cs:line 254

c#
.net-core
nopcommerce
asked on Stack Overflow Jan 26, 2019 by VSB

2 Answers

2

That seems issues with nop v4.0 as it was loading uninstalled plugins in memory, and has been resolved in v4.10. Either you can upgrade to the updated version or check following fix, if it would work!

Change

public object Resolve(Type type)
{
    return GetServiceProvider().GetRequiredService(type);
}

To

public object Resolve(Type type)
{
    if (type.IsSubclassOf(typeof(BasePlugin))) {
        return null;
    }
    return GetServiceProvider().GetRequiredService(type);
}
answered on Stack Overflow Jan 27, 2019 by Divyang Desai
0

I'm getting this error when I forgot to register service with it interface

Eg :

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)
   {
      //register service manager
      builder.RegisterType<SearchFilterService>().As<ISearchFilterService>().InstancePerLifetimeScope();
      builder.RegisterType<ElasticSearchService>().As<IElasticSearchService>().InstancePerLifetimeScope();          
   }

   /// <summary>
   /// Gets order of this dependency registrar implementation
   /// </summary>
   public int Order => 1;
}
answered on Stack Overflow May 23, 2020 by Isanka Thalagala

User contributions licensed under CC BY-SA 3.0