Building .NET Framework 4.8 project in Docker fails with "Reached end of stream before end of read"

Viewed 1043

My Dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /projectName
COPY . .
RUN nuget restore
COPY . .
WORKDIR /repoName/projectName
RUN msbuild ./projectName.csproj /p:Configuration=Debug

Locally, the msbuild step gives me no problems. Without a .dockerignore file, the build fails:

Process is terminated due to StackOverflowException.

When I add a .dockerignore file that looks like this...

./.git
./.idea
./.vs
./gen
./packages
./irrelevantProject1
./irrelevantProject2
# etc

...the build fails again, but with a different error message:

CompilerServer: server failed - server rejected the request 'Error reading response: Reached end of stream before end of read.' - b6c5574e-55ea-4d7d-adb3-e156ebd65296
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB6006: "csc.exe" exited with code -2146232797. [C:\repoName\projectName\projectName.csproj]
Done Building Project "C:\repoName\projectName\projectName.csproj" (default targets) -- FAILED.

Build FAILED.

"C:\repoName\projectName\projectName.csproj" (default target) (1) ->
(CoreCompile target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Roslyn\Microsoft.CSharp.Core.targets(71,5): error MSB6006: "csc.exe" exited with code -2146232797. [C:\repoName\projectName\projectName.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:31.66
The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; msbuild ./projectName.csproj /p:Configuration=Debug' returned a non-zero code: 1

I've been stuck on this problem for days. Any advice would be greatly appreciated.

2 Answers

Allocating more memory to the build solved this problem.

docker build -t projectName -m 4g .

A collegue of mine points me this compiler bug https://github.com/dotnet/roslyn/issues/59336

According to comments, compiler crashes on anonymous delegate function declaration and also when preview features are used (like "!!" syntax) but then removed from recent compiler version.

Fix is not yet available in recent Docker SDK .Net 4.8 image

Related