Paket icon indicating copy to clipboard operation
Paket copied to clipboard

UseWindowsService() - The process was terminated due to an unhandled exception.

Open jwu-dharmo opened this issue 2 years ago • 0 comments

I started a gRPC project from Visual Studio 2022 with .Net 6.0.

Steps:

  1. Microsoft.Extensions.Hosting.WindowsServices (6.0.0)
  2. Add this line to program.cs builder.Host.UseWindowsService();
  3. Build the project
  4. Created a Window Service with the sc command:

sc create "Grpc Test2" binPath= C:\Users\WuJ22\source\repos\GrpcService1\GrpcService1\bin\Release\net6.0\GrpcService1.exe start= auto DisplayName= "Grpc Test2"

Please provide a succinct description of your issue.

  1. The service failed to start
  2. Event log has this message:

Application: GrpcService1.exe CoreCLR Version: 6.0.622.26707 .NET Version: 6.0.6 Description: The process was terminated due to an unhandled exception. Exception Info: System.NotSupportedException: The content root changed from "C:\Windows\system32" to "C:\Users\WuJ22\source\repos\GrpcService1\GrpcService1\bin\Release\net6.0". Changing the host configuration using WebApplicationBuilder.Host is not supported. Use WebApplication.CreateBuilder(WebApplicationOptions) instead. at Microsoft.AspNetCore.Builder.ConfigureHostBuilder.ConfigureHostConfiguration(Action1 configureDelegate) at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.UseContentRoot(IHostBuilder hostBuilder, String contentRoot) at Microsoft.Extensions.Hosting.WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(IHostBuilder hostBuilder, Action1 configure) at Program.<Main>$(String[] args) in C:\Users\WuJ22\source\repos\GrpcService1\GrpcService1\Program.cs:line 9

Expected behavior

  1. Service to start without error

Actual behavior

  1. Service wouldn't start

None at the moment

jwu-dharmo avatar Jul 11 '22 15:07 jwu-dharmo