๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

[ASP.Net] Fixing ASP.NET Core Windows Service Startup Error in .NET 6

๋ฐœํ–‰์ผ: Feb, 2025
์กฐํšŒ์ˆ˜: 1
๋‹จ์–ด์ˆ˜: 144

Table of Contents

Error Occurrence

If you encounter an error after building an ASP.NET Core project in .NET 6, registering it as a Windows Service, and starting the service, follow these steps to diagnose and fix the issue.


Checking the Event Log

First, open the Event Log Viewer and check the exception message.

Event Log Viewer Error

Navigate to Windows Logs โ†’ Application and look for a .NET Runtime Error. This log typically reveals the exact location in the code where the exception occurred.


Fixing the Issue

If the error is caused by code accessing configuration settings from appsettings.json, you can resolve it by specifying the ContentRootPath when creating the application builder.

var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
    Args = args,
    ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default,
});

For unknown reasons, when running the application as a Windows Service, the ContentRootPath may be set incorrectly. By explicitly setting it as shown above, the application should function properly.


Tags: #.NET 6#ASP.NET Core#Windows Service#Event Log Viewer#Configuration#ContentRootPath
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.