From the idea of ββGreg Roses, I developed this little fragment. Please note that I tried to adhere to naming conventions.
public void SaveAllAssemblies() { Assembly[] asslist = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly ass in asslist) { FileInfo fi = new FileInfo(ass.Location); if (!fi.Extension.Equals(".exe", StringComparison.InvariantCultureIgnoreCase)) { var assName = fi.Name; var assConverter = new FormatterConverter(); var assInfo = new SerializationInfo(typeof(Assembly), assConverter); var assContext = new StreamingContext(); using (var assStream = new FileStream(assName, FileMode.Create)) { BinaryFormatter bformatter = new BinaryFormatter(); ass.GetObjectData(assInfo, assContext); bformatter.Serialize(assStream, assInfo); assStream.Close(); } } } }
But some assemblies are not marked as serializable, such as mscorlib.dll. Therefore, is this probably only a partial solution?
Despite the fact that you can serialize some assemblies, I suggest using FileInfo, as shown in the example, will generate a list and check the original nodes.
source share