Skip to content

Commit

Permalink
Sgen: Update GetTempAssemblyName according to #46499 (#57026)
Browse files Browse the repository at this point in the history
* Update GetTempAssemblyName according to #46499

In #46499 we corrected Compilation.GetTempAssemblyName in order for it to be not deterministic under .NET Core.
In this PR we update the generated filename to match the new logic.

* Update Microsoft.XmlSerializer.Generator.csproj

* Update SGen.cs

Avoid using external dependency

* Update Microsoft.XmlSerializer.Generator.csproj

Avoid using external dependency

* Update Sgen.cs

Fixed compilation
  • Loading branch information
TalAloni committed Aug 17, 2021
1 parent f0ad279 commit 4699992
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/libraries/Microsoft.XmlSerializer.Generator/src/Sgen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -555,7 +556,19 @@ private static string GetXmlSerializerAssemblyName(Type type, string defaultName

private 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.Create().ComputeHash(valueBytes);
return ReadUInt32BigEndian(hash);
}

private static uint ReadUInt32BigEndian(byte[] value)
{
return (uint)(value[0] << 24 | value[1] << 16 | value[2] << 8 | value[3]);
}

private static void ParseReferences()
Expand Down

0 comments on commit 4699992

Please sign in to comment.