dotnet / dotnet/sdk

`dotnet {build, restore}` crashing and hanging in Docker

Open
#45,751 1 comment 0 reactions 1 assignee Claimed by @joeloff View on GitHub
Area-CLI untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

Hi,

When I try to run `dotnet build` or `dotnet restore` in Docker, then the process crashes. Sometimes it even hangs, tying up the user's shell session.

# Trace

```console
$ docker run --rm -it hello dotnet restore

Welcome to .NET 8.0!
---------------------
SDK Version: 8.0.401

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate, view the instructions: https://aka.ms/dotnet-https-linux

----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at Regex1_Scan(RegexRunner, ReadOnlySpan`1)
```

# Bad process state

Several problems are happening.

`dotnet restore` triggers a null pointer error, instead of generating a security report for Npgsql.

When `dotnet restore` runs inside a `docker run --rm -it hello bash` REPL session, then it triggers a null pointer error and crashes back to the container shell prompt (`#`).

However, when `dotnet restore` runs as a one-off command with `docker run --rm -it hello dotnet restore`, then the same null pointer error shows but the process hangs, failing to terminate the process and return control back to the _host_ shell (e.g. `$` on macOS).

For comparison, `dotnet restore` appears to work fine when run directly on the host (at least for macOS and Windows hosts). And a dozen other programming languages work just fine in Fedora (v41) in Docker (v27). .NET is the first one I've seen segfault with a Hello World project since Swift and Z*g.

As an aside, installing `nuget` via DNF and running `nuget` results in SIGABRT crashes. Something's rotten in the state of .NET.

# Dockerfile

```dockerfile
FROM fedora:41
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
ENV DOTNET_ROOT=/root/.dotnet
ENV PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
RUN dnf install -y \
curl \
krb5-libs \
libicu \
openssl-libs && \
curl -LO https://dot.net/v1/dotnet-install.sh && \
chmod +x dotnet-install.sh && \
./dotnet-install.sh --version 8.0.401 && \
rm dotnet-install.sh
COPY . /src
WORKDIR /src
```

# hello.csproj

```xml


Exe
net8.0
hello
enable
enable
true



```

# Hello.cs

```cs
using Npgsql;

Console.WriteLine("Hello World!");

Console.WriteLine($"Database connector: {ServerCompatibilityMode.Redshift}");

//
// Example privacy violation.
// A social security number leaks through application logs.
//
Console.Write("SSN: ");
var ssn = Console.ReadLine();
// Console.WriteLine("Registered user.");
Console.WriteLine($"Registered user. SSN: {ssn}");
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.