Docker Community Forums

Share and learn in the Docker community.

Could not resolve a service of type 'System.Net.Http.HttpClient' for the parameter 'httpClient' of method 'Configure' on type 'MyProject.WindowsService.Startup

Need help on this. I have this code in my Startup.cs that runs fine when I run my WindowsService normally.

When I run it inside docker, I get an error in my try catch block:

Error in Startup.ConfigureServices() IDX10000: The parameter 'certificate' cannot be a 'null' or an empty object. Parameter name: certificate ServicePointManager.ServerCertificateValidationCallback Application startup exception: System.Exception: Could not resolve a service of type 'System.Net.Http.HttpClient' for the parameter 'httpClient' of method 'Configure' on type 'MyProject.WindowsService.Startup'. ---> System.InvalidOperationException: No service for type 'System.Net.Http.HttpClient' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.AspNetCore.Hosting.Internal.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) --- End of inner exception stack trace --- at Microsoft.AspNetCore.Hosting.Internal.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.Internal.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()'

My docker file looks like this:

FROM microsoft/aspnet:4.7.2-windowsservercore-ltsc2016
EXPOSE 50500
WORKDIR /WinService
COPY dotnet-sdk-2.2.104-win-x64.exe ./
RUN Start-Process ‘dotnet-sdk-2.2.104-win-x64.exe’ ‘/quiet’ -PassThru | Wait-Process;
COPY WindowsService/bin/Release/* ./
COPY WindowsService/launcher.bat .
ENTRYPOINT [“MyProject.WindowsService.exe”, “–consolemode=true”]