Paket
Paket copied to clipboard
UseWindowsService() - The process was terminated due to an unhandled exception.
I started a gRPC project from Visual Studio 2022 with .Net 6.0.
Steps:
- Microsoft.Extensions.Hosting.WindowsServices (6.0.0)
- Add this line to program.cs
builder.Host.UseWindowsService();
- Build the project
- 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.
- The service failed to start
- 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(Action
1 configureDelegate) at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.UseContentRoot(IHostBuilder hostBuilder, String contentRoot) at Microsoft.Extensions.Hosting.WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(IHostBuilder hostBuilder, Action
1 configure) at Program.<Main>$(String[] args) in C:\Users\WuJ22\source\repos\GrpcService1\GrpcService1\Program.cs:line 9
Expected behavior
- Service to start without error
Actual behavior
- Service wouldn't start
None at the moment