question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
peterhuenecommented, Jan 14, 2019

@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!

1reaction
peterhuenecommented, Jan 14, 2019

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/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet build reporting "PE image does not have metadata ...
The text "PE image does not have metadata." is reported and dotnet build exits with 1. The DLL and PDB files are produced...
Read more >
PE image does not have metadata." for MAUI Android ...
Cause for "XABBA7009: System.InvalidOperationException: PE image does not have metadata." for MAUI Android release image using Visual Studio ...
Read more >
Unable to compile Xamarin.Android project in VS 2022 ...
The mobile app is going from Android 8 to Android 12. ... XAPRAS7009: System.InvalidOperationException: PE image does not have metadata.
Read more >
PE image doesn't contain managed metadata.
I see this error has appeared a few times here since 2015 but I don't see any permanent resolution.
Read more >
BadImageFormatException on ServiceStack.OrmLite. ...
I get the following error: Microsoft.Common. ... System.BadImageFormatException: PE image does not have metadata. at System.Reflection.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found