Runtime: Assembly(Definition|Reference).GetAssemblyName() do not match handling of neutral culture of AssemblyName.GetAssemblyName()

Created on 12 Dec 2018  Â·  11Comments  Â·  Source: dotnet/runtime

``` C#
using System;
using System.IO;
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;

class Program
{
static void Main()
{
var coreAssemblyPath = typeof(object).Assembly.Location;

    Console.WriteLine(AssemblyName.GetAssemblyName(coreAssemblyPath));

    using (var peReader = new PEReader(File.OpenRead(coreAssemblyPath)))
    {
        var mdReader = peReader.GetMetadataReader();
        Console.WriteLine(mdReader.GetAssemblyDefinition().GetAssemblyName());
    }
}

}


System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
System.Private.CoreLib, Version=4.0.0.0, PublicKeyToken=7cec85d7bea7798e
```

Notice culture=neutral vs culture omitted.

area-System.Reflection.Metadata easy up-for-grabs

All 11 comments

@nguerrera Although technically breaking I think we should change the SRM behavior to match System.Reflection. Agreed?

Yes, agreed.

Is this change still up for grabs or has anyone implemented it already? If still pending, I can give it a shot

I looked up a previous issue where building the repo locally was a problem, and as per that thread I ran build.sh on my mac, it did install lot of packages, but at the end failed with below error.
Should I open an issue for this?
The command "/corefx/src/Native/build-native.sh" x64 Debug OSX outconfig netcoreapp-OSX-Debug-x64 -portable" exited with code 1.

@harish-kumar13 seems still up for grabs.

For the build failure can you dig a little deeper, look at console detail /build logs? 1 just means failed somehow

@harish-kumar13, @danmosemsft Is somebody working on this? If not, I would take it.

Oh i thought someone else took it, havent worked on it, please go ahead
with it.

On Mon, May 6, 2019, 1:37 PM Stano Peťko notifications@github.com wrote:

@harish-kumar13 https://github.com/harish-kumar13, @danmosemsft
https://github.com/danmosemsft Is somebody working on this? If not, I
would take it.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/dotnet/corefx/issues/34008#issuecomment-489707078,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFZIGEL353H6RFFFSJWSGBLPUBUG5ANCNFSM4GJZ6YCA
.

@tmat, @nguerrera, @danmosemsft

I looked at this and it is harder than (I) expected.

I tracked it down to the AssemblyTableReader.GetCulture() method, which is used in MetadataReader.GetAssemblyName(). StringHandle returned by GetCulture() is _nil_, so there is no culture name.

I used some hex editor to look inside the dll. There is Culture=neutral in several places. All of them are just after assembly name. But PEReader is reading these information on some other place and there is no culture there. AssemblyTableReader class expects offset for culture to be written right after the offset of the name, but value at the culture's offset is 0.

So I do not know where exactly is the real problem. Maybe the format of the assembly is a bit different than PEReader is expecting? So the culture should be read in different place inside it? Or maybe the whole AssemblyName info (name, version, culture and public key) should be read from some other place?

@satano If you are not working on this anymore, I would like to give it a shot.

@ThyPillow I am not working at it. I did not understand where is the problem, as I stated in my last comment (and nobody answered).

The value at the culture offset in the assembly table is 0 because it is emitted as such.
The compiler is normalizing the culture name in AssemblyIdentity, treating neutral as invariant culture name and setting string.empty to its value.

As it's saved as null instead of empty, my proposal is to treat the value as empty when reading and building the AssemblyName, similar to what assemblyspec.cpp appears to be doing.
At display time AssemblyNameFormatter is doing what the compiler is doing in reverse order, treating an empty culture name as neutral.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omariom picture omariom  Â·  3Comments

EgorBo picture EgorBo  Â·  3Comments

jzabroski picture jzabroski  Â·  3Comments

noahfalk picture noahfalk  Â·  3Comments

chunseoklee picture chunseoklee  Â·  3Comments