aspnet / aspnet-docker

[Archived] ASP.NET Core Docker images for 1.x. Go to https://github.com/dotnet/dotnet-docker for 2.1 and up.
https://asp.net
719 stars 171 forks source link

System.TypeInitializationException on dotnet restore #383

Closed AleF83 closed 6 years ago

AleF83 commented 6 years ago

I'm trying to build docker image but it fails on dotnet restore.

Steps to reproduce the issue

Dockerfile

# Stage 1: Copy csproj files
FROM debian:stable-slim AS csprojImage
COPY . ./
RUN mkdir csproj && cp --parent ./src/**/*.csproj /csproj

# Stage 1: Build
FROM microsoft/aspnetcore-build:2.0.5-2.1.4 AS buildImage

COPY  --from=csprojImage /csproj /build
COPY . /build
RUN dotnet restore
RUN dotnet publish --output /dist/ --configuration Release
...

.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
    <PackageReference Include="Minio.NetCore" Version="1.0.7" />
    <PackageReference Include="MongoDB.Driver" Version="2.5.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
  </ItemGroup>

</Project>

Expected behavior

Image built

Actual behavior

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.Cli.Utils.Product' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'System.Reflection.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. An attempt was made to load a program with an incorrect format.

at Microsoft.DotNet.Cli.Utils.Product.GetProductVersion() at Microsoft.DotNet.Cli.Utils.Product..cctor() --- End of inner exception stack trace --- at Microsoft.DotNet.Cli.MulticoreJitProfilePathCalculator.CalculateProfileRootPath() at Microsoft.DotNet.Cli.MulticoreJitActivator.StartCliProfileOptimization() at Microsoft.DotNet.Cli.MulticoreJitActivator.TryActivateMulticoreJit() at Microsoft.DotNet.Cli.Program.Main(String[] args) Aborted

Additional information (e.g. issue happens only occasionally)

Doesn't happen on build without docker

Output of dotnet --info

NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.13
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.1.4/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54

Output of docker info

Containers: 9
 Running: 7
 Paused: 0
 Stopped: 2
Images: 96
Server Version: 18.03.0-ce-rc1
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 6c55f98695e902427906eed2c799e566e3d3dfb5
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.75-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: RJN5:Q4O3:AOUH:2CDC:PEMQ:EE27:IEQM:GP6H:QL3P:YDCJ:OXDE:PYKO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 79
 Goroutines: 86
 System Time: 2018-03-01T09:03:41.57699114Z
 EventsListeners: 2
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
AleF83 commented 6 years ago

Ok, Restart solved the problem..