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

[release/7.0] Reverting: Set AssemblyName.ProcessorArchitecture for compatibility (#81101) #83565

Merged
merged 1 commit into from
Apr 7, 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
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand All @@ -9,8 +9,8 @@

The System.Reflection.Metadata library is built-in as part of the shared framework in .NET Runtime. The package can be installed when you need to use it in other target frameworks.</PackageDescription>
<PackageReadmeFile>README.md</PackageReadmeFile>
<ServicingVersion>1</ServicingVersion>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ServicingVersion>2</ServicingVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
Expand Down
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 @@ -3090,13 +3090,8 @@ public void GetAssemblyName()

if (PlatformDetection.HasAssemblyFiles)
{
Assembly a = typeof(MetadataReader).Assembly;
AssemblyName name = MetadataReader.GetAssemblyName(AssemblyPathHelper.GetAssemblyLocation(a));
Assert.Equal(new AssemblyName(a.FullName).ToString(), name.ToString());

#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete
Assert.Equal(ProcessorArchitecture.MSIL, name.ProcessorArchitecture);
#pragma warning restore SYSLIB0037
Assembly a = typeof(MetadataReaderTests).Assembly;
Assert.Equal(new AssemblyName(a.FullName).ToString(), MetadataReader.GetAssemblyName(AssemblyPathHelper.GetAssemblyLocation(a)).ToString());
}
}
}
Expand Down