Sdk: error MSB4018: System.InvalidOperationException: PE image does not have metadata.

Created on 8 Dec 2018  路  5Comments  路  Source: dotnet/sdk

Steps to reproduce

Failure is happening when I try to dotnet restore a .csproj with the following packages (inside a docker container):

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="4.19.4" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
    <PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
    <PackageReference Include="Moq" Version="4.7.63" />
    <PackageReference Include="Akka.MultiNodeTestRunner" Version="1.3.10" />
    <PackageReference Include="Akka.TestKit" Version="1.3.10" />
    <PackageReference Include="Akka.TestKit.Xunit2" Version="1.3.10" />
  </ItemGroup>

If I remove package <PackageReference Include="Akka.MultiNodeTestRunner" Version="1.3.10" /> the process goes correctly, so it must be something related to it.

Expected behavior

Some packages download normally, and it finishes with this error:
error MSB4018: System.InvalidOperationException: PE image does not have metadata. (followed by many other errors.
Another error happens just before this one: /usr/share/dotnet/sdk/2.1.200/Microsoft.Common.CurrentVersion.targets(2106,5): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly.

Actual behavior

Environment data

dotnet --info output:

.NET Command Line Tools (2.1.200)

Product Information:
Version: 2.1.200
Commit SHA-1 hash: 2edba8d7f1

Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/2.1.200/

Microsoft .NET Core Shared Framework Host

Version : 2.0.7
Build : 2d61d0b043915bc948ebf98836fefe9ba942be11

(I tried with dotnet core 2.2, but the same happens)

All 5 comments

Does this repro only inside a docker container? Can you provide the full stack?

Well, I don't have windows, only linux hahaha My system is Linux Deepin 15.8 (debian-based, similar to Ubuntu 18.04).
My docker is:

$ docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:51 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:15 2018
  OS/Arch:          linux/amd64
  Experimental:     false

This is my Dockerfile:

FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1
RUN apt-get update && apt-get install -y \
    unzip \
    screen \
    expect \
    libleveldb-dev \
    git-core \
    wget \
    curl \
    vim \
    nano \
    cron \
    man \
    iputils-ping \
    net-tools

RUN apt-get install -y gnupg2 gnupg gnupg1
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
RUN echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | tee /etc/apt/sources.list.d/mono-official-stable.list
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
RUN mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
RUN wget -q https://packages.microsoft.com/config/ubuntu/18.04/prod.list
RUN mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
RUN apt-get update && apt-get install -y apt-transport-https dotnet-sdk-2.1.200

# APT cleanup to reduce image size
RUN rm -rf /var/lib/apt/lists/*

It's strange, because only this single package Akka.MultiNodeTestRunner fails... I don't know how to debug this in details, tried to put nuget with verbosity detailed, but no extra useful is displayed in my opinion. Any possible steps to get more information?

This is the complete log: https://pastebin.com/0hXUcRCt

This is an issue with how Akka.MultiNodeTestRunner is packaged.

The problem is here. This is copying platform-specific assets into what should be only managed dependencies to reference. Additionally, I see a ton of native files from the framework itself in lib/netcoreapp1.1; this suggests that this package also published in a self-contained fashioned.

The correct layout for this package should be only managed assemblies to reference (both at compile-time and run-time) in lib/ and put the native assets into runtimes/ to copy for run-time only.

While we do get a warning for each PE without managed metadata in lib/netcoreapp1.1 for this package, 16.x MSBuild does fail with an internal error:

usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018: The "ResolveAssemblyReference" task failed unexpectedly. [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Unexpected CopyLocal flag. [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.CopyLocalStateUtility.IsCopyLocal(CopyLocalState state) [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.LogResults(ReferenceTable dependencyTable, List`1 idealAssemblyRemappings, List`1 idealAssemblyRemappingsIdentities, ArrayList generalResolutionExceptions) [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,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) [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.Tasks.ResolveAssemblyReference.Execute() [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/Users/peterhuene/tmp/repro/repro.csproj]
/usr/local/share/dotnet/sdk/3.0.100-preview-009812/Microsoft.Common.CurrentVersion.targets(2114,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/Users/peterhuene/tmp/repro/repro.csproj]

The RAR task should probably be more resilient to incorrect packages by warning then ignoring any non-managed PEs in lib/.

@igormcoelho Thanks for reporting this to us! I'm resolving this as an external issue. It does not appear to be possible to use Akka.MultiNodeTestRunner from non-Windows platforms. Please open an issue with the Akka.NET repro and reference the comment above.

A simple repro would be:

dotnet new console
dotnet add package akka.multinodetestrunner
dotnet build

I'll open another issue on MSBuild regarding the RAR task failure.

Thank you!

Thanks a lot @peterhuene ! This is a very important tool... I'll see what they can do for us.

Was this page helpful?
0 / 5 - 0 ratings