Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Security.Cryptography.Algorithms" />
<Reference Include="System.Security.Cryptography.Primitives" />
<Reference Include="System.Text.Encoding.Extensions" />
<Reference Include="System.Text.RegularExpressions" />
<Reference Include="System.Threading" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;

namespace System.Xml.Serialization
{
Expand Down Expand Up @@ -89,7 +90,17 @@ internal TextWriter Source

internal static string GetTempAssemblyName(AssemblyName parent, string? ns)
{
return parent.Name + ".XmlSerializers" + (ns == null || ns.Length == 0 ? "" : "." + ns.GetHashCode());
return parent.Name + ".XmlSerializers" + (ns == null || ns.Length == 0 ? "" : "." + GetPersistentHashCode(ns));
}

private static uint GetPersistentHashCode(string value)
{
byte[] valueBytes = System.Text.Encoding.UTF8.GetBytes(value);
using (SHA512 sha512 = SHA512.Create())
{
byte[] hash = sha512.ComputeHash(valueBytes);
return (uint)(hash[0] << 24 | hash[1] << 16 | hash[2] << 8 | hash[3]);
}
}
}
}