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

Sgen: Update GetTempAssemblyName according to #46499 #57026

Merged
merged 5 commits into from
Aug 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we include our own implementation of ReadUInt32BigEndian() here because the framework version is netstandard2.1, while this tool targets netstandard2.0? If that's the case, I think this is fine.

@HongGit, do we have any plans to update the targetframework for this tool, or are we sticking to netstandard2.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, we are still sticking to netstandard2.0. If there is a need to update, we could consider to.

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

private static void ParseReferences()
Expand Down