Search code examples
asp.net.netubuntuserver

A .NET API service shows (code=exited, status=203/EXEC) when Deploying to an Ubuntu Server


I want to deploy a WebAPI create with .NET 5 to a Hetzner server, I have deployed it based on the steps of this website Deploy .NET. Everything works fine, until I run the Service and check its status, it shows an error with my WebApi.dll

root@ubuntu:/# systemctl status  MinAPIservice.service
● MinAPIservice.service - ASP .NET Web Application
     Loaded: loaded (/etc/systemd/system/MinAPIservice.service; enabled; preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Tue 2023-06-13 09:58:40 UTC; 1s ago
    Process: 52726 ExecStart=/usr/bin/dotnet /var/www/MinAPI/MinWebApi.dll (code=exited, status=203/EXEC)
   Main PID: 52726 (code=exited, status=203/EXEC)
        CPU: 775us

And to find the problem I have run the following command /etc/systemd/system# /usr/bin/dotnet /var/www/MinAPI/WebApi.dll in the system directory, and shows the following error:

root@ubuntu:/etc/systemd/system# /usr/bin/dotnet /var/www/MinAPI/WebApi.dll
You must install or update .NET to run this application.

App: /var/www/MinAPI/WebApi.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '5.0.0' (x64)
.NET location: /usr/lib/dotnet/

The following frameworks were found:
   6.0.16 at [/root/.dotnet/shared/Microsoft.AspNetCore.App]
  7.0.5 at [/root/.dotnet/shared/Microsoft.AspNetCore.App]

Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=5.0.0&arch=x64&rid=ubuntu.23.04-x64

Now my Server shows 503 - Service Unavailable ...

I have tried to Install .NET 5.0 , but it's no longer supported for Ubuntu 23.04, also tried to install .NET 6.0 still the same, I want to find a solution to this error to run my API using Swagger.


Solution

  • Error says you don't have .NET 5 framework installed, but you have higher versions so you can run it on a higher version, but you must configure roll-forward behavior for the application.

    Note that since using this option lets the application run on a different framework version than the one for which it was designed, it may result in unintended behavior due to changes between versions of a framework.

    Or you could upgrade the framework version of your API to the latest .NET 7.