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
@@ -1,13 +1,16 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Reflection;
using System.Buffers.Binary;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;

namespace System.Xml.Serialization
{
Expand Down Expand Up @@ -89,7 +92,14 @@ 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" + (string.IsNullOrEmpty(ns) ? "" : $".{GetPersistentHashCode(ns)}");
}

private static uint GetPersistentHashCode(string value)
{
byte[] valueBytes = Encoding.UTF8.GetBytes(value);
byte[] hash = SHA512.HashData(valueBytes);
return BinaryPrimitives.ReadUInt32BigEndian(hash);
}
}
}