dotnet/runtime

Problems reading embedded resources using system.reflection.metadata

Open

#29.511 geöffnet am 10. Mai 2019

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)C# (5.445 Forks)batch import
area-System.Reflection.Metadatahelp wanted

Repository-Metriken

Stars
 (17.886 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)

Beschreibung

As part of building a feature in ASP.NET Core I was using System.Reflection.Metadata to crack an assembly and extract an embedded resource to validate its contents (in a test).

I was using a snippet from https://github.com/dotnet/corefx/issues/23372 to do so, and I kept seeing a test fail intermittently on debug build on OS X in our CI build.

It seemed like sometimes it extracted the resource correctly and some other times it produced garbage. I was able to capture one of the generated assemblies that caused a test failure and I was able to produce a minimal repro (see below).

resourceextractor.zip

Upon debugging the repro a bit, I could see that the code used to calculate the offset to the resources was not correct and it was pointing past the resources directory. I can think one of 3 things are happening:

  • There is a bug in peReader.TryGetDirectoryOffset.
  • The generated assembly on Mac OS is somehow malformed.**
  • The code snippet I used is not correct in all cases. (I can't tell for sure because it's the first time I use the API).

image

Any ideas?

Contributor Guide