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

ResolveAssemblyReference fails with error MSB4018 on Linux: "InvalidOperationException: PE image does not have metadata" #382

Closed phil-harmoniq closed 6 years ago

phil-harmoniq commented 6 years ago

Steps to reproduce the issue

(e.g. copy your Dockerfile or docker-compose.yml file here)

  1. The repo in question: https://github.com/phil-harmoniq/vue-template
  2. Successfully builds in my CI pipeline and on my Linux desktop: https://travis-ci.org/phil-harmoniq/vue-template
  3. Try to build this on a MacBook

Expected behavior

Building my Docker image.

Actual behavior

Running dotnet publish -c Release in my Dockerfile results in the following during the restore step:

Restoring packages for /vue-template/vue-template.csproj...
  Restore completed in 45.13 ms for /vue-template/vue-template.csproj.
  Generating MSBuild file /vue-template/obj/vue-template.csproj.nuget.g.props.
  Generating MSBuild file /vue-template/obj/vue-template.csproj.nuget.g.targets.
  Restore completed in 569.53 ms for /vue-template/vue-template.csproj.
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly. [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018: System.InvalidOperationException: PE image does not have metadata. [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at System.Reflection.PortableExecutable.PEReader.GetMetadataBlock() [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder) [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader) [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.Shared.AssemblyNameExtension.GetAssemblyNameEx(String path) in E:\A\_work\17\s\src\Shared\AssemblyNameExtension.cs:line 153 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.SetPrimaryAssemblyReferenceItem(ITaskItem referenceAssemblyName) in E:\A\_work\17\s\src\Tasks\AssemblyDependency\ReferenceTable.cs:line 624 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.SetPrimaryItems(ITaskItem[] referenceAssemblyFiles, ITaskItem[] referenceAssemblyNames, ArrayList exceptions) in E:\A\_work\17\s\src\Tasks\AssemblyDependency\ReferenceTable.cs:line 502 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.Tasks.ReferenceTable.ComputeClosure(DependentAssembly[] remappedAssembliesValue, ITaskItem[] referenceAssemblyFiles, ITaskItem[] referenceAssemblyNames, ArrayList exceptions) in E:\A\_work\17\s\src\Tasks\AssemblyDependency\ReferenceTable.cs:line 1634 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute(FileExists fileExists, DirectoryExists directoryExists, GetDirectories getDirectories, GetAssemblyName getAssemblyName, GetAssemblyMetadata getAssemblyMetadata, GetLastWriteTime getLastWriteTime, GetAssemblyRuntimeVersion getRuntimeVersion, GetAssemblyPathInGac getAssemblyPathInGac, IsWinMDFile isWinMDFile, ReadMachineTypeFromPEHeader readMachineTypeFromPEHeader) in E:\A\_work\17\s\src\Tasks\AssemblyDependency\ResolveAssemblyReference.cs:line 2160 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute() in E:\A\_work\17\s\src\Tasks\AssemblyDependency\ResolveAssemblyReference.cs:line 2939 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() in E:\A\_work\17\s\src\Build\BackEnd\TaskExecutionHost\TaskExecutionHost.cs:line 631 [/vue-template/vue-template.csproj]
/usr/share/dotnet/sdk/2.1.4/Microsoft.Common.CurrentVersion.targets(2041,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() in E:\A\_work\17\s\src\Build\BackEnd\Components\RequestBuilder\TaskBuilder.cs:line 787 [/vue-template/vue-template.csproj]
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
The terminal process terminated with exit code: 1

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

I don't know whether this is an issue with the aspnetcore-build image or the Mac Docker client itself. If you know of a better repo to post this in, please let me know. For the record, the dotnet publish command works fine when run natively (not in 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: 22
 Running: 0
 Paused: 0
 Stopped: 22
Images: 70
Server Version: 17.12.0-ce
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: 89623f28b87a6004d4b785663257362d1658a729
runc version: b2567b37d7b75eb4cf325b77297b140ea686ce8f
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.60-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: QUJ6:7J7I:YD4Y:7HJ4:WXPA:CHYB:QQFR:UB6Y:N6PG:ARLH:FZKD:4M3O
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 21
 Goroutines: 40
 System Time: 2018-03-01T06:02:02.970892468Z
 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
natemcmaster commented 6 years ago

I couldn't reproduce this using the steps you gave. Building the image passed just fine on my macBook. The error message seems to indicate there was a problem reading a .dll file. Are you volume mounting your local folder into the docker container?

Stealthfox commented 6 years ago

I had the same issue with a similar setup. Docker version 17.12.0-ce, Mac OS X 10.13 using dotnet SDK 2.1.4.

I resolved my issue by using aspnetcore-build:2.0-jessie rather than aspnetcore-build:2.0

natemcmaster commented 6 years ago

This issue was moved to Microsoft/msbuild#3085