Skip to content

Moved AssemblyName helpers to managed #62866

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

Merged
merged 24 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b051da8
Moved ComputePublicKeyToken to managed
VSadov Dec 15, 2021
63104c4
Managed assembly name parsing (adapted from nativeaot)
VSadov Jan 14, 2022
b03d76d
Fix for HostActivation failures.
VSadov Jan 14, 2022
7ac1bcf
PR feedback (RuntimeAssemblyName is back to CoreRT + other comments)
VSadov Jan 15, 2022
6543736
remove AssemblyNameNative::Init form the .hpp
VSadov Jan 15, 2022
ae5ba2f
remove AppX compat ifdef
VSadov Jan 15, 2022
6f1d6d1
renamed instance fields to convention used in C#
VSadov Jan 15, 2022
911a530
`Argument_InvalidAssemblyName` should be `InvalidAssemblyName`. M…
VSadov Jan 15, 2022
da210a5
remove `this.`
VSadov Jan 18, 2022
023c5f9
PR feedback (assign to fileds, bypass properties)
VSadov Jan 18, 2022
650ffa5
missed this change in the rebase
VSadov Jan 19, 2022
895fbf5
"low-hanging fruit" perf tweaks.
VSadov Jan 19, 2022
f8e61c3
move one-user helpers to where they are used.
VSadov Jan 19, 2022
666093a
removed ActiveIssue for #45032
VSadov Jan 19, 2022
2a20695
remove AssemblyNameHelpers.cs form corelib
VSadov Jan 19, 2022
5956c62
Remove the List when detecting duplicates. Support PublicKey.
VSadov Jan 22, 2022
094d666
whitespace
VSadov Jan 22, 2022
e82b448
Fix managed implementation to match the new tests.
VSadov Jan 23, 2022
330b950
Some minor cleanup.
VSadov Jan 23, 2022
c716408
Do not validate culture too early
VSadov Jan 24, 2022
9b6d86c
PR feedback
VSadov Jan 24, 2022
d76dd03
use SR.InvalidAssemblyName
VSadov Jan 24, 2022
d70d256
Report the input string when throwing FileLoadException
VSadov Jan 24, 2022
8bc2d9a
tweaked couple comments
VSadov Jan 24, 2022
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 @@ -11,18 +11,6 @@ namespace System.Reflection
{
public sealed partial class AssemblyName : ICloneable, IDeserializationCallback, ISerializable
{
public AssemblyName(string assemblyName)
{
if (assemblyName == null)
throw new ArgumentNullException(nameof(assemblyName));
if ((assemblyName.Length == 0) ||
(assemblyName[0] == '\0'))
throw new ArgumentException(SR.Format_StringZeroLength);

_name = assemblyName;
nInit();
}

internal AssemblyName(string? name,
byte[]? publicKey,
byte[]? publicKeyToken,
Expand All @@ -44,9 +32,6 @@ internal AssemblyName(string? name,
_flags = flags;
}

[MethodImpl(MethodImplOptions.InternalCall)]
internal extern void nInit();

// This call opens and closes the file, but does not add the
// assembly to the domain.
[MethodImpl(MethodImplOptions.InternalCall)]
Expand All @@ -58,9 +43,6 @@ internal static AssemblyName GetFileInformationCore(string assemblyFile)
return nGetFileInformation(fullPath);
}

[MethodImpl(MethodImplOptions.InternalCall)]
private extern byte[]? ComputePublicKeyToken();

internal void SetProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm)
{
#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,5 +1091,10 @@ public static bool IsPrimitive(RuntimeTypeHandle typeHandle)
{
return typeHandle.ToEETypePtr().IsPrimitive && !typeHandle.ToEETypePtr().IsEnum;
}

public static byte[] ComputePublicKeyToken(byte[] publicKey)
{
return System.Reflection.AssemblyNameHelpers.ComputePublicKeyToken(publicKey);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,10 @@
<Compile Include="Internal\Reflection\Extensions\NonPortable\CustomAttributeSearcher.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="System\Reflection\AssemblyNameHelpers.StrongName.cs" />
<Compile Include="System\Reflection\AssemblyNameHelpers.cs" />
<Compile Include="System\Reflection\AssemblyNameLexer.cs" />
<Compile Include="System\Reflection\AssemblyNameParser.cs" />
<Compile Include="System\Reflection\RuntimeAssembly.cs" />
<Compile Include="System\Reflection\RuntimeAssemblyName.cs" />
<Compile Include="System\Reflection\AssemblyNameHelpers.cs" />
<Compile Include="System\Reflection\AssemblyRuntimeNameHelpers.cs" />
<Compile Include="System\Reflection\Attribute.CoreRT.cs" />
<Compile Include="System\Reflection\Assembly.CoreRT.cs" />
<Compile Include="System\Reflection\AssemblyName.CoreRT.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,6 @@ namespace System.Reflection
{
public sealed partial class AssemblyName : ICloneable, IDeserializationCallback, ISerializable
{
public AssemblyName(string assemblyName)
: this()
{
if (assemblyName == null)
throw new ArgumentNullException(nameof(assemblyName));
if ((assemblyName.Length == 0) ||
(assemblyName[0] == '\0'))
throw new ArgumentException(SR.Format_StringZeroLength);

_name = assemblyName;
RuntimeAssemblyName runtimeAssemblyName = AssemblyNameParser.Parse(_name);
runtimeAssemblyName.CopyToAssemblyName(this);
}

private byte[] ComputePublicKeyToken()
{
return AssemblyNameHelpers.ComputePublicKeyToken(_publicKey);
}

private static AssemblyName GetFileInformationCore(string assemblyFile)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_AssemblyName_GetAssemblyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,8 @@

namespace System.Reflection
{
[System.Runtime.CompilerServices.ReflectionBlocked]
public static partial class AssemblyNameHelpers
internal static partial class AssemblyNameHelpers
{
//
// Converts an AssemblyName to a RuntimeAssemblyName that is free from any future mutations on the AssemblyName.
//
public static RuntimeAssemblyName ToRuntimeAssemblyName(this AssemblyName assemblyName)
{
if (assemblyName.Name == null)
throw new ArgumentException();

AssemblyNameFlags flags = assemblyName.Flags;
AssemblyContentType contentType = assemblyName.ContentType;
#pragma warning disable SYSLIB0037 // AssemblyName.ProcessorArchitecture is obsolete
ProcessorArchitecture processorArchitecture = assemblyName.ProcessorArchitecture;
#pragma warning restore SYSLIB0037
AssemblyNameFlags combinedFlags = CombineAssemblyNameFlags(flags, contentType, processorArchitecture);
byte[]? pkOriginal;
if (0 != (flags & AssemblyNameFlags.PublicKey))
pkOriginal = assemblyName.GetPublicKey();
else
pkOriginal = assemblyName.GetPublicKeyToken();

// AssemblyName's PKT property getters do NOT copy the array before giving it out. Make our own copy
// as the original is wide open to tampering by anyone.
byte[]? pkCopy = null;
if (pkOriginal != null)
{
pkCopy = new byte[pkOriginal.Length];
((ICollection<byte>)pkOriginal).CopyTo(pkCopy, 0);
}

return new RuntimeAssemblyName(assemblyName.Name, assemblyName.Version, assemblyName.CultureName, combinedFlags, pkCopy);
}

//
// These helpers convert between the combined flags+contentType+processorArchitecture value and the separated parts.
//
Expand All @@ -55,19 +22,9 @@ internal static AssemblyContentType ExtractAssemblyContentType(this AssemblyName
return (AssemblyContentType)((((int)flags) >> 9) & 0x7);
}

internal static ProcessorArchitecture ExtractProcessorArchitecture(this AssemblyNameFlags flags)
{
return (ProcessorArchitecture)((((int)flags) >> 4) & 0x7);
}

public static AssemblyNameFlags ExtractAssemblyNameFlags(this AssemblyNameFlags combinedFlags)
internal static AssemblyNameFlags ExtractAssemblyNameFlags(this AssemblyNameFlags combinedFlags)
{
return combinedFlags & unchecked((AssemblyNameFlags)0xFFFFF10F);
}

internal static AssemblyNameFlags CombineAssemblyNameFlags(AssemblyNameFlags flags, AssemblyContentType contentType, ProcessorArchitecture processorArchitecture)
{
return (AssemblyNameFlags)(((int)flags) | (((int)contentType) << 9) | ((int)processorArchitecture << 4));
}
}
}

This file was deleted.

Loading