Skip to content
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 @@ -356,7 +356,7 @@ internal static unsafe RuntimeAssembly InternalLoad(AssemblyName assemblyName,
byte[]? publicKeyOrToken;
if ((publicKeyOrToken = assemblyName.RawPublicKeyToken) != null)
{
flags |= ~AssemblyNameFlags.PublicKey;
flags &= ~AssemblyNameFlags.PublicKey;
}
else if ((publicKeyOrToken = assemblyName.RawPublicKey) != null)
{
Expand Down
22 changes: 22 additions & 0 deletions src/libraries/System.Reflection/tests/AssemblyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,28 @@ public void GetSatelliteAssemblyNeg()
Assert.Throws<System.IO.FileNotFoundException>(() => (typeof(AssemblyTests).Assembly.GetSatelliteAssembly(CultureInfo.InvariantCulture)));
}

[Fact]
public void AssemblyLoadWithPublicKey()
{
AssemblyName an = new AssemblyName("System.Runtime");

Assembly a = Assembly.Load(an);

byte[] publicKey = a.GetName().GetPublicKey();
Assert.True(publicKey.Length > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do the public key and PKT have defined lengths (eg., 8 and 160) and if so, could we assert the lengths of each here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they do. We have AssemblyName tests that verify that.

This test only requires that the public key and public key token are non-empty to cover the desired scenario.

an.SetPublicKey(publicKey);

Assembly a1 = Assembly.Load(an);
Assert.Equal(a, a1);

// Force the public key token to be created
Assert.True(an.GetPublicKeyToken().Length > 0);

// Verify that we can still load the assembly
Assembly a2 = Assembly.Load(an);
Assert.Equal(a, a2);
}

[Fact]
public void AssemblyLoadFromString()
{
Expand Down