Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting: Set AssemblyName.ProcessorArchitecture for compatibility (#80581) #84028

Merged
merged 3 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ public static unsafe AssemblyName GetAssemblyName(string assemblyFile)
peReader = new PEReader((byte*)safeBuffer.DangerousGetHandle(), (int)safeBuffer.ByteLength);
MetadataReader mdReader = peReader.GetMetadataReader(MetadataReaderOptions.None);
AssemblyName assemblyName = mdReader.GetAssemblyDefinition().GetAssemblyName();

AssemblyFlags aFlags = mdReader.AssemblyTable.GetFlags();
#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete
assemblyName.ProcessorArchitecture = CalculateProcArch(peReader, aFlags);
#pragma warning restore SYSLIB0037

return assemblyName;
}
finally
Expand All @@ -107,42 +101,6 @@ public static unsafe AssemblyName GetAssemblyName(string assemblyFile)
}
}

private static ProcessorArchitecture CalculateProcArch(PEReader peReader, AssemblyFlags aFlags)
{
// 0x70 specifies "reference assembly".
// For these, CLR wants to return None as arch so they can be always loaded, regardless of process type.
if (((uint)aFlags & 0xF0) == 0x70)
return ProcessorArchitecture.None;

PEHeaders peHeaders = peReader.PEHeaders;
switch (peHeaders.CoffHeader.Machine)
{
case Machine.IA64:
return ProcessorArchitecture.IA64;
case Machine.Arm:
return ProcessorArchitecture.Arm;
case Machine.Amd64:
return ProcessorArchitecture.Amd64;
case Machine.I386:
{
CorFlags flags = peHeaders.CorHeader!.Flags;
if ((flags & CorFlags.ILOnly) != 0 &&
(flags & CorFlags.Requires32Bit) == 0)
{
// platform neutral.
return ProcessorArchitecture.MSIL;
}

// requires x86
return ProcessorArchitecture.X86;
}
}

// ProcessorArchitecture is a legacy API and does not cover other Machine kinds.
// For example ARM64 is not expressible
return ProcessorArchitecture.None;
}

private static AssemblyNameFlags GetAssemblyNameFlags(AssemblyFlags flags)
{
AssemblyNameFlags assemblyNameFlags = AssemblyNameFlags.None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,7 @@ public void GetAssemblyName()
Assert.Equal(new AssemblyName(a.FullName).ToString(), name.ToString());

#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete
Assert.Equal(ProcessorArchitecture.MSIL, name.ProcessorArchitecture);
Assert.Equal(ProcessorArchitecture.None, name.ProcessorArchitecture);
#pragma warning restore SYSLIB0037
}
}
Expand Down