How to create RunAndSave Assembly using System.Reflection.Emit in .NET 6?
In the .NET 6 documentation for the AssemblyBuilder class in System.Reflection.Emit there is an example of how to build an assembly. The example can be made to compile and work in .NET 6 by changing
AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly
(aName, AssemblyBuilderAccess.RunAndSave);
to
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly
(aName, AssemblyBuilderAccess.Run);
and by commenting out
ab.Save(aName.Name + ".dll");
The example will run but you cannot save the created assembly becausethe DefineDynamicAssembly() method does not exist in the .NET 6 version of System.AppDomain, the RunAndSave field of AssemblyBuilderAccess does not exist in the .NET 6 version of System.Reflection.Emit, and the Save() method of AssemblyBuilder does not exist in the .NET version of System.Reflection.Emit. Those three items are only in the .NET Framework 4.8 version.
Is there a way to save the created assembly in .NET 6?