No constructor was found that had all the dependencies satisfied

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 Jahre weitere
I'm trying to update plugin from version 3.90 to 4.0 but when I try to install it I get this error:

"No constructor was found that had all the dependencies satisfied."

"Nop.Core.NopException: No constructor was found that had all the dependencies satisfied. ---> Autofac.Core.Registration.ComponentNotRegisteredException: The requested service 'System.Web.HttpContextBase' 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.
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.Resolve(IComponentContext context, Type serviceType)
   at Autofac.Extensions.DependencyInjection.AutofacServiceProvider.GetRequiredService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Nop.Core.Infrastructure.NopEngine.Resolve(Type type)
   at Nop.Core.Infrastructure.NopEngine.<ResolveUnregistered>b__15_0(ParameterInfo parameter)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Nop.Core.Infrastructure.NopEngine.ResolveUnregistered(Type type)
   --- End of inner exception stack trace ---
   at Nop.Core.Infrastructure.NopEngine.ResolveUnregistered(Type type)
   at Nop.Core.Plugins.PluginDescriptor.Instance[T]()
   at Nop.Core.Plugins.PluginDescriptor.Instance()
   at Nop.Web.Areas.Admin.Controllers.PluginController.Install(IFormCollection form)"


Can someone help me with this?

Thanks,

Marija
6 Jahre weitere
Hello,
You can't use
 System.Web.HttpContextBase httpContext
in Asp.Net Core (nopCommerce 4.0) in Constructor.
6 Jahre weitere
Please use
 "IHttpContextAccessor _httpContextAccessor"


So your code will look like


using Microsoft.AspNetCore.Http.Features;
...
...
...

private readonly IHttpContextAccessor _httpContextAccessor;

...
...
public YourService(IHttpContextAccessor httpContextAccessor)
        {
          
            this._httpContextAccessor = httpContextAccessor;
        }




This will help you.

Same issue
6 Jahre weitere
Thanks on your answer. I made a change and now I have another problem in this lines:

1. var licencePath = _httpContextAccessor.Server.MapPath("~/Plugins/PluginName/Text.txt");

2. var currentUrl = _httpContextAccessor.Request.Url != null ? _httpContextAccessor.Request.Url.Host.Replace("www.", "") : null;

Error 1: IHttpContextAccessor does not contain definition for 'Server'

Error 2: IHttpContextAccessor does not contain definition for 'Request'


Do you have any suggestion?
6 Jahre weitere
marijag wrote:


1. var licencePath = _httpContextAccessor.Server.MapPath("~/Plugins/PluginName/Text.txt");

Error 1: IHttpContextAccessor does not contain definition for 'Server'



_httpContextAccessor doesn't support Server class.
You can use something like

private readonly IHostingEnvironment _hostingEnvironment;
and  
_hostingEnvironment.ContentRootPath + "\\Plugins\\PluginName\\Text.txt";




Hope it will work.
6 Jahre weitere
marijag wrote:

2. var currentUrl = _httpContextAccessor.Request.Url != null ? _httpContextAccessor.Request.Url.Host.Replace("www.", "") : null;

Error 2: IHttpContextAccessor does not contain definition for 'Request'



For get host value use
_httpContextAccessor.HttpContext.Request.Host
6 Jahre weitere
Thank you for your answers. It helped me a lot.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.