I am trying to run a simple program on CentOS.
The program:
using System;
namespace helloworld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
returnHello();
}
static string returnHello()
{
return "hwdy ha";
}
}
}
My publish settings are:
- Configuration: Release|Any CPU
- Target framework: netcoreapp2.1
- Deployment mode: self contained
- target runtime: linux-x64
- target location: binReleasenetcoreapp2.1publish
In a terminal I run
dotnet publish –self-contained -r linux-x64 -c release
Then take the folder publish and copy it over to my CentOS machine.
using file helloworld, I see the file details:
ELF 64-bit LSB executable, x86-64,version 1(SYSV), dynamically linked
(uses shared libs), for GNU/linux.2.6.32,
BuildID[sha1]=0x22d087f79061d441f9f6d007bf336f380c1214db, stripped
using uname -r:
3.2.0-3-amd64
In CentOS, I go into the publish folder and run: bash helloworld. In response, I get
helloworld: cannot execute binary file
.
I am not sure what I am missing here, to me it seems the file is targeting the right OS but I cannot execute the file in CentOS. Any help is appreciated. Thanks
2
Answers
Don’t run
bash
on a binary executable, just run it directly with./helloworld
.bash
is a shell-script interpreter and refuses to read non-text files. e.g.If
./helloworld
doesn’t work, also trystrace ./helloworld
andldd ./helloworld
to check for a bad ELF interpreter (dynamic linker) path embedded in the executable.TLDR: You need to switch to a more recent os for .NET Core, like CentOS 7 or Debian 9.
First, based on the
/etc/*release
output, you are using Debian wheezy (aka Debian 7). A couple of things to note: This was released in 2013 and End-of-Life’d in 2016. In other words, you are using an operating system that’s not supported anymore, by anyone. It’s not supported by .NET Core. It’s not supported by Debian itself. (It’s certainly not supported by CentOS)Second, every release of .NET Core has a list of platforms (and specific versions of platforms) it supports. Older versions of those platforms lack features, compatibility, or something else that makes .NET Core unsuitable for running there.
.NET Core 2.1 supports these operating systems. For Debian, it only supports Debian 9 (and, I assume, later versions as they are released).
Since .NET Core supports Debian 9, it makes use of a number of features in the C library (
glibc
) that require a recent version ofglibc
. Debian 7 doesn’t have that recent version ofglibc
, so it can’t run .NET Core 2.1 applications.You should try a more recent version of Debian, CentOS or some other Linux distribution. I know that .NET Core 2.1 works well on RHEL (and CentOS by extension). It should work well on recent versions of Debian and Ubuntu too.
There are a couple of ways to modify .NET Core and to work around this error, but it’s rather advanced and would leave you with unable to update to new point releases of .NET Core, so I don’t reccommend it: you can bootstrap .NET Core itself (as in, re-compile .NET Core itself) to support Debian 7 and then use that to run your application.