UseWindowsService() - The process was terminated due to an unhandled exception.
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 2.1k
- Forks
- 528
- Avg merge
- 1d 12m
- Merged PRs (30d)
- 54
Description
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
$(String[] args) in C:\Users\WuJ22\source\repos\GrpcService1\GrpcService1\Program.cs:line 9
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.
Expected behavior
- Service to start without error
Actual behavior
- Service wouldn't start
None at the moment
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the referenced Program.cs line 9 and the UseWindowsService call in a .NET 6 gRPC project. Reproduce the service startup using the sc command and inspect the hosting configuration exception and related Windows service hosting behavior. Done means the service starts without the reported unhandled exception, with a regression test or documented reproduction if the project supports it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, grpc
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100