For as far as i have used this, AssemblyGenerator.GenerateAssemblyBytes() seems to work for most assemblies present in application memory, but unfortunately not for 'System.Private.CoreLib'.
It specifically throws;
System.ArgumentException: 'Type cannot be found: "System.Runtime.CompilerServices.RefSafetyRulesAttribute, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e" Arg_ParamName_Name'
in GetTypeHandle() of AssemblyMetadata.cs
I suppose this is a bug?