Is there any way to compute a cryptographic hash of an assembly in .NET Standard? It's very important that this hash stays the same unless something is modified inside the assembly (eg. that it was rebuilt).
For example, assuming .NET Framework is used, we do the following
var assembly = Assembly.GetCallingAssembly();
var hash = new Hash(assembly);
var hashVal = hash.GenerateHash(new SHA512Managed());
I have tried to serialize the assembly as shown below but I get the error
Unhandled Exception: System.Runtime.Serialization.SerializationException: Type 'System.Reflection.RuntimeAssembly' in Assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' is not marked as serializable.
var assembly = Assembly.GetCallingAssembly();
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, assembly);
SHA512 sha = SHA512.Create();
var hash = Convert.ToBase64String(sha.ComputeHash(stream));