public byte[] SerializedStateToMemory() { SerializedState serializedState = new SerializedState(); serializedState.Config = Config; serializedState.UpdatesToApply = UpdatesToApply; serializedState.LogItems = Logger.LogItems; serializedState.State = State; using (var memoryStream = new MemoryStream()) { new BinaryFormatter().Serialize(memoryStream, serializedState); memoryStream.Flush(); memoryStream.Close(); return memoryStream.GetBuffer(); } }