Search code examples
c#dotnet-cli.net-7.0

C#: .NET 7.0 console helloworld crash on Linux? (built but fails to run)


Version: dotnet-sdk: 7.0.100-rc.2.22477.23 from snap.
Basically it builds fine, but fails to run on linux.

What config should I set to run it?

target=net7.0, unpublished: (e.g. bin/Debug/net7.0/helloworld)

seg fault on load.

target=net7.0, published by: dotnet publish -r linux-x64 -f net7.0

seg fault on load.

target=net6.0, unpublished:

Error: "You must install .NET to run this application."

target=net6.0, published by: dotnet publish -r linux-x64 -f net6.0

OK

target=windows, net6.0/7.0, unpublished by: dotnet publish -r win10-x64 -f net6.0 (or 7.0)

OK (on windows)

PS:
dotnet sdk 6.0 is out of question because it is is broken out-of-box: does not work with vscode; dotnet cli broken.

The program is a minimal helloworld.

using System;
class Program {
    static void Main(string[] args) {
        Console.WriteLine("Hello, World!");
    }
}
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net462;net6.0;net7.0</TargetFrameworks>
    <LangVersion>8</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

(.net framework is OK on Mono and windows)


Solution

  • snap dotnet packages seems problematic.

    $ snap list
    core18             20220831                       2566   latest/stable    canonical**   base
    core20             20220826                       1623   latest/stable    canonical**   base
    dotnet-sdk         7.0.100-rc.2.22477.23          182    7.0/beta         dotnetcore**  classic
    dotnet-runtime-60  6.0.10                         25     latest/stable    dotnetcore**  -
    
    1. dotnet-runtime 6.0/7.0: missing symbol during dynamic linker.
      $ DOTNET_ROOT=/snap/dotnet-runtime-60/25/ ./bin/Debug/net6.0/aaa

    Failed to load /snap/dotnet-runtime-60/25/shared/Microsoft.NETCore.App/6.0.10/libcoreclr.so, error: /snap/dotnet-runtime-60/25/shared/Microsoft.NETCore.App/6.0.10/../../../lib/x86_64-linux-gnu/librt.so.1:
    undefined symbol: __clock_nanosleep, version GLIBC_PRIVATE
    Segmentation fault (core dumped)

    1. dotnet-sdk 7.0rc2: if target=net7.0, output program crash during dynamic linker.
      $ ./bin/Debug/net7.0/aaa

    Segmentation fault (core dumped)

    Both two issues specific to snap packages, not on packages from https://dotnet.microsoft.com/en-us/download

    Side note on runtime trouble shooting:

    • dotnet publish download binaries, thus irrelavant to local runtime.
      Probably using: ~/.nuget/packages/microsoft.netcore.app.runtime.*
    • Trouble shooting runtime searching, in addition to strace:

      export COREHOST_TRACE=1
      export COREHOST_TRACEFILE=host.txt