A green apple isn’t a banana, picturing the topic of this article around .NET versions

Why Your .NET Service Won’t Start When .NET Is Already Installed

A Windows service failed to start on a Windows Server Core machine with four .NET runtimes installed. But why?

It is release time and we deploy to a pre-production environment. One application gets deployed, then another, then the last one fails. It is a Windows Service application, and PowerShell only tells us CouldNotStartService.

In this article, we walk through how we found the cause. Along the way, we explain each concept.

A Generic Error

Our starting point was Start-Service -Name 'MyService' failing with CouldNotStartService.

This error says that Windows tried to start the service and it did not work. It does not say why.

Technically, it is what PowerShell reports when a start request made to the Service Control Manager fails. The Service Control Manager is the Windows component that starts and stops services. To find the reason, we need to correlate the System and Application event logs for the same attempt.

Collecting the Evidence

The following script saves the relevant events to a text file and opens it in Notepad. It is a practical way to gather the logs and copy them for analysis outside of the Windows Server Core CLI window.

We run it on the machine where the start failed. If the failure is more than 30 minutes old, we move $since to just before the attempt. Redact credentials, connection strings and customer data before sharing the file to an AI model!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
$since = (Get-Date).AddMinutes(-30)
$file = Join-Path $env:TEMP "MyService-$(Get-Date -Format 'yyyyMMdd-HHmmss').txt"

& {
    "Log window: $since to $(Get-Date)"
    $service = Get-Service -Name 'MyService'

    "`nWindows Service Control Manager events"
    Get-WinEvent -FilterHashtable @{
        LogName = 'System'
        ProviderName = 'Service Control Manager'
        StartTime = $since
    } -ErrorAction SilentlyContinue | Where-Object {
        $_.Message -like "*$($service.Name)*" -or
        $_.Message -like "*$($service.DisplayName)*"
    } | Select-Object TimeCreated, Id, Message -First 10 |
        Format-List | Out-String -Width 200

    "`n.NET Runtime errors"
    Get-WinEvent -FilterHashtable @{
        LogName = 'Application'
        ProviderName = '.NET Runtime'
        Level = 1, 2
        StartTime = $since
    } -ErrorAction SilentlyContinue | Select-Object TimeCreated, ProviderName, Id, Message -First 15 |
        Format-List | Out-String -Width 200

    "`nAll application errors"
    Get-WinEvent -FilterHashtable @{
        LogName = 'Application'
        Level = 1, 2
        StartTime = $since
    } -ErrorAction SilentlyContinue | Select-Object TimeCreated, ProviderName, Id, Message -First 15 |
        Format-List | Out-String -Width 200
} 2>&1 | Out-File -LiteralPath $file -Encoding utf8

Write-Host "Saved to: $file"
notepad.exe "$file"

-ErrorAction SilentlyContinue keeps Get-WinEvent from writing a “No events were found” error into the file when a filter matches nothing. It also hides real errors, such as access denied, so run the script from an elevated PowerShell.

The dedicated .NET Runtime section is a refinement we added after the troubleshooting session. The reason for it is simple: a list limited to the 15 newest errors from every application can be filled by a noisy component, pushing out the one event that matters. We ran it, and it gave us what we needed to find the cause of the issue.

Reading the Events

We found three events that piqued our interest:

  • Service Control Manager event 7009 reported that the service had not connected within 30,000 milliseconds.
  • Event 7000 reported that the service had failed to start.
  • .NET Runtime event 1023 gave the actual reason:
1
2
3
4
5
6
7
App: D:\Applications\MyService\MyCompany.MyService.exe
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
.NET location: C:\Program Files\dotnet\

The following frameworks were found:
  10.0.10 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

To understand what this event is telling us, we need to talk about runtimes. A runtime is the software that must be present on a machine for your application to execute. What many of us call “.NET” is, in fact, several of them, installed side by side. Our server confirmed it:

1
& 'C:\Program Files\dotnet\dotnet.exe' --list-runtimes

The output listed Microsoft.NETCore.App versions 6.0.36, 8.0.0, 10.0.1 and 10.0.10. For Microsoft.AspNetCore.App, it listed only 10.0.10.

In plain words, Microsoft.NETCore.App is the base engine, and Microsoft.AspNetCore.App is an additional set of libraries for web features. Having version 6 of the first does not give you version 6 of the second.

Technically, these are two distinct shared frameworks. According to Microsoft’s launch troubleshooting guide, the .NET Runtime contains only Microsoft.NETCore.App, while the ASP.NET Core Runtime is the one that brings Microsoft.AspNetCore.App. The guide’s advice for a missing framework is to “select a runtime download that contains the missing framework, and then install it”. In our case, reinstalling the .NET 6 Runtime would not have helped, because it only provides Microsoft.NETCore.App, which we already had. What we needed was the ASP.NET Core 6 Runtime, which provides the missing Microsoft.AspNetCore.App version 6.

Why Version 10 Does Not Replace Version 6

It is tempting to think that a newer version can always run an older application. By default, .NET does not work that way.

The application asks for version 6. .NET accepts a suitable 6.x, but it will not jump to another major version on its own.

Technically, this is the roll-forward policy. The version selection documentation states that Minor applies when nothing is specified. A Major policy exists, and roll-forward can be set in the runtime configuration, through the DOTNET_ROLL_FORWARD environment variable or with the --roll-forward option. We did not try it on this service, and Microsoft warns that rolling forward may result in unintended behavior due to changes between framework versions.

What the Project File Told Us

The service targeted .NET 6, and its project file also pulled in health check packages that depend on ASP.NET Core. Our project snippet contained these references:

1
2
3
4
5
<TargetFramework>net6.0</TargetFramework>
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="8.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="9.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client.Net6" Version="1.0.1" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />

The health check packages were added to expose health check endpoints to the observability tools the company uses to monitor whether applications are up or down.

A PackageReference brings in a library from NuGet, the .NET package manager. A FrameworkReference declares that the application relies on a set of libraries expected to be already installed on the machine.

Technically, the FrameworkReference element adds the ASP.NET Core shared framework to the project. Projects using the Microsoft.NET.Sdk.Web SDK reference it implicitly, so you may depend on it without ever writing that line. The package versions 8.0.0 and 9.0.0 do not select the shared runtime, and Net6 in a package name does not set the target framework.

Fixing It

With the proper approval, the answer is to install ASP.NET Core Runtime 6.0.36 for Windows x64 alongside .NET 10. The base x64 .NET Runtime 6.0.36 was already on the machine. Microsoft’s download page recommends the Hosting Bundle on Windows, which adds IIS support, but our Windows service needs neither that bundle nor the SDK.

Important note: .NET 6 has been out of support since November 12, 2024, and .NET 8, also installed on this server, reached the end of its support on November 10, 2026. Treat this as a temporary recovery for a company that still uses old runtime versions and plan a move to .NET 10.

After the installation, rerun --list-runtimes and confirm that Microsoft.AspNetCore.App 6.0.36 appears. When it is safe to do so, start the service from an elevated PowerShell and check that its status is Running:

1
2
Start-Service -Name 'MyService' -ErrorAction Stop
Get-Service -Name 'MyService'

After installing the ASP.NET Core 6 Runtime, --list-runtimes showed `Microsoft.AspNetCore.App 6.0.36`, and the service started with a Running status.

Conclusion

“Is .NET installed?” was the wrong question. The useful one was which shared framework, in which version and architecture, the application asks for. The generic PowerShell error will not tell you, and neither will the Service Control Manager timeout, but the .NET Runtime event next to them will.

Follow me

Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.

Credit: Photo by alleksana on Pexels (https://www.pexels.com/photo/apple-and-banana-4451843/).

License GPLv3 | Terms
Built with Hugo
Theme Stack designed by Jimmy