Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: System.Xml.Serialization: Compiler.GetTempAssemblyName is not deterministic under .NET Core #46499

Merged
10 commits merged into from
Jul 18, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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" + (ns == null || ns.Length == 0 ? "" : "." + GetPersistentHashCode(ns));
TalAloni marked this conversation as resolved.
Show resolved Hide resolved
}

private static uint GetPersistentHashCode(string value)
{
byte[] valueBytes = Encoding.UTF8.GetBytes(value);
byte[] hash = System.Security.Cryptography.SHA512.Create().ComputeHash(valueBytes);
TalAloni marked this conversation as resolved.
Show resolved Hide resolved
return (uint)(hash[0] << 24 | hash[1] << 16 | hash[2] << 8 | hash[3]);
}
}
}