diff --git a/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj b/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
index 526cc0ea846179..205d11ef42f99a 100644
--- a/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
+++ b/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
@@ -567,6 +567,7 @@
+
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs
index 20522dca69f2e9..71e2fdd1ed1fef 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compiler.cs
@@ -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
{
@@ -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);
}
}
}