dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.72k stars 1.07k forks source link

You must install .NET to run this application / .NET location: Not found #39259

Closed SeppPenner closed 8 months ago

SeppPenner commented 8 months ago

Describe the bug

.Net8 project (ASP.Net on base of background service) with Microsoft.Extensions.Hosting.Systemd fails with .NET location: Not found on systemctl start.

To Reproduce

Provide a .Net8 project with Microsoft.Extensions.Hosting.Systemd, add a service file (MyService.service) to /etc/systemd/system that looks like this, do a systemctl daemon-reload and try to start the service using systemctl start MyService.

Service file

[Unit]
Description=MyService
After=syslog.target
After=network.target

[Service]
Type=notify
WorkingDirectory=/srv/MyService
ExecStart=/srv/MyService/MyService
SyslogIdentifier=MyService
User=root
Restart=always
RestartSec=5
EnvironmentFile=/etc/systemd/system/myserviceenv
Environment=DOTNET_ROLL_FORWARD=Major

[Install]
WantedBy=multi-user.target

Environment file

DOTNET_DefaultDiagnosticPortSuspend=0
DOTNET_DiagnosticPorts=/diag/myservice.sock,nosuspend

Exceptions (if any)

Mar 06 15:34:51 testserver MyService[2701]: You must install .NET to run this application.
Mar 06 15:34:51 testserver MyService[2701]: App: /srv/MyService/MyService
Mar 06 15:34:51 testserver MyService[2701]: Architecture: x64
Mar 06 15:34:51 testserver MyService[2701]: App host version: 8.0.2
Mar 06 15:34:51 testserver MyService[2701]: .NET location: Not found
Mar 06 15:34:51 testserver MyService[2701]: Learn more:
Mar 06 15:34:51 testserver MyService[2701]: https://aka.ms/dotnet/app-launch-failed
Mar 06 15:34:51 testserver MyService[2701]: Download the .NET runtime:
Mar 06 15:34:51 testserver MyService[2701]: https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linux-x64&os=ubuntu.22.04&apphost_version=8.0.2
Mar 06 15:34:51 testserver systemd[1]: MyService.service: Main process exited, code=exited, status=131/n/a

Further technical details

Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/8.0.200/

.NET workloads installed: There are no installed workloads to display.

Host: Version: 8.0.2 Architecture: x64 Commit: 1381d5ebd2

.NET SDKs installed: 8.0.200 [/usr/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 8.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found: None

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download



--> Reinstalling dotnet didn't work nor did a daemon reload and a reboot help here. A similar issue was https://github.com/dotnet/sdk/issues/38999, but it was resolved with some antivirus issue. In our case, this code worked properly with Net7 and fails after updating everything to Net8 (Without any specific other changes).
dotnet-issue-labeler[bot] commented 8 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

SeppPenner commented 8 months ago

After adding Environment=DOTNET_ROOT=/usr/share/dotnet to the service file and doing a systemctl daemon-reload, this issue is fixed. However, I wanted to know, why this issue can occur since dotnet is obviously installed correctly and it worked like this with .Net7 without any changes in particular to the code...

baronfel commented 8 months ago

is the dotnet --info you've provided from the host that's failing? How have you installed .NET on this host? Which packages and feeds specifically?

SeppPenner commented 8 months ago

is the dotnet --info you've provided from the host that's failing?

Yes.

How have you installed .NET on this host? Which packages and feeds specifically?

Following https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-2204. So basically, just:

sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0
SeppPenner commented 8 months ago

I guess, I found the issue: I didn't follow https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-2204, but https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian...