Sdk: dotnet build reporting "PE image does not have metadata" with no details.

Created on 23 Apr 2016  路  19Comments  路  Source: dotnet/sdk

Steps to reproduce

I'm hitting this in a private repro building an assembly building against the full CLR.

Expected behavior

Builds clean or reports the errant image not containing metadatea

Actual behavior

Compilation Succeeds with 0 errors and warnings. Elapsed time is reported. The text "PE image does not have metadata." is reported and dotnet build exits with 1.
The DLL and PDB files are produced and ildasm is able to report metadata for the assembly.

Environment data

dotnet --info output:
.NET Command Line Tools (1.0.0-rc2-002444)

Product Information:
Version: 1.0.0-rc2-002444
Commit Sha: ada4e363c0

Runtime Environment:
OS Name: Windows
OS Version: 10.0.14329
OS Platform: Windows
RID: win10-x64

Bug

Most helpful comment

@piotroko I'm seeing this issue again with coreclr 2.0 preview-1. When our nuget package assembly releases a native assembly in the same directory, the following builds fail.

All 19 comments

@jaredpar @cdmihai does the error message "PE image does not have metadata" mean something to either of you? Is CSC producing this?

@dantraMSFT can you provide a minimal repro?

@piotrpMSFT - I haven't been able to make it too minimal but I did managed to isolate it down to the single project and as set of packages. How should I get it to you?

@piotrpMSFT never seen it. Seems like a resource that gets written in the obj? https://github.com/search?q=PEImageDoesNotHaveMetadata&type=Code&utf8=%E2%9C%93

@dantraMSFT a zip with command line repro steps would be nice.

@dantraMSFT can you share the repro with @cdmihai?

This error is actually coming from System.Reflection.MetadataReader:

https://github.com/dotnet/corefx/blob/d0dc5fc099946adc1035b34a8b1f6042eddb0c75/src/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEReader.cs#L337

@tmat has more context but I'm guessing the compiler is being asked to reference a file that isn't actually a valid PE.

@cdmihai @tmat, I trust you guys will figure out whose fix this is :)

any updates here?

Haven't had the time to look into this yet. I'll try to repro it tomorrow.
Thanks @jaredpar for the indication. I'll take a look what references are sent to csc.

Apparently one Nuget package has a native dll:

C:\Issue2660\build\packages\Microsoft.Management.Infrastructure.Native\1.0.0-rc3lib\net451\Microsoft.Management.Infrastructure.Native.Unmanaged.dll

MakeRunnable attempts to redirect it and tries to read the metadata. PEReader throws because it can't read the metadata:

System.InvalidOperationException occurred
  HResult=-2146233079
  Message=PE image does not have metadata.
  Source=System.Reflection.Metadata
  StackTrace:
       at System.Reflection.PortableExecutable.PEReader.GetMetadataBlock()
       at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder)
       at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader)
       at Microsoft.DotNet.Cli.Compiler.Common.BindingRedirectGenerator.GetAssemblyInfo(LibraryAsset arg) in C:\projects\cli_2\src\Microsoft.DotNet.Compiler.Common\BindingRedirectGenerator.cs:line 184
  InnerException: 

@pakrym

This file should not be in the lib folder if it's native, it should be in native folder.

Ideally, there should be an error message about this so people do not open issues thinking it's a CLI bug. Who should check for valid nuget package consistency?

  • nuget pack
  • dotnet pack
  • nuget restore
  • dotnet restore
  • ProjectContextBuilder.Build when it creates the package descriptions
  • some other package checker that should run somewhere in the CLI / nuget so all commands benefit from it

@cdmihai let's fix the error message coming from CLI, and also open two issues for NuGet:

  • [x] nuget pack should warn if a bad package is being produced
  • [x] nuget restore should warn if a bad package got restored

Bad needs to be defined, here we're saying that a bad package is one that has non-managed assets in a directory expected to carry managed code only.

Confirmed with @cdmihai that this was fixed by dotnet/cli#2744

@piotroko I'm seeing this issue again with coreclr 2.0 preview-1. When our nuget package assembly releases a native assembly in the same directory, the following builds fail.

Removing .vs folder and rebuilding app resolved problem in my case (caused by blue screen when debug was running)

We figured out the proper way to pack native assemblies into a nuget package and the problem is solved. :)

Hi,
I am having the same problem. What is the proper way to pack native assemblies into a nuget package? Should I add the native libraries to the /lib/native folder of the Nuget package or should I add it to the /native folder?
Thank you

Getting this after upgrading to netcoreapp2.1. I'm guessing the native library is SQLite.

Source is https://github.com/voltagex/YAMS, run build.ps1 and you get the error.

I just saw this out of nowhere in a Xamarin project. No changes made since the last time it successfully built and deployed. Cleaning and rebuilding fixed it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomaslevesque picture thomaslevesque  路  3Comments

dasMulli picture dasMulli  路  3Comments

gkhanna79 picture gkhanna79  路  3Comments

krwq picture krwq  路  3Comments

srayuws picture srayuws  路  3Comments