public static void SaveSnapshotFile(PrintingStateSnapshot state, Stream fileStream) { SnapshotContainer container = new SnapshotContainer(); container.type = SnapshotTypeStateAndRemainingGCode; container.version = ContainerVersion; container.snapshot = state; System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(container.GetType()); try { x.Serialize(fileStream, container); } catch (InvalidOperationException ex) { throw new IOException("Failed to write state file.", ex); } }