diff options
Diffstat (limited to 'MediaBrowser.Common/Configuration/ConfigurationHelper.cs')
| -rw-r--r-- | MediaBrowser.Common/Configuration/ConfigurationHelper.cs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs index 64c2e87de..8c904b0db 100644 --- a/MediaBrowser.Common/Configuration/ConfigurationHelper.cs +++ b/MediaBrowser.Common/Configuration/ConfigurationHelper.cs @@ -36,21 +36,25 @@ namespace MediaBrowser.Common.Configuration configuration = Activator.CreateInstance(type); } - // Take the object we just got and serialize it back to bytes - var newBytes = xmlSerializer.SerializeToBytes(configuration); - - // If the file didn't exist before, or if something has changed, re-save - if (buffer == null || !buffer.SequenceEqual(newBytes)) + using (var stream = new MemoryStream()) { - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - // Save it after load in case we got new items - File.WriteAllBytes(path, newBytes); - } + xmlSerializer.SerializeToStream(configuration, stream); - return configuration; - } + // Take the object we just got and serialize it back to bytes + var newBytes = stream.ToArray(); + + // If the file didn't exist before, or if something has changed, re-save + if (buffer == null || !buffer.SequenceEqual(newBytes)) + { + Directory.CreateDirectory(Path.GetDirectoryName(path)); + // Save it after load in case we got new items + File.WriteAllBytes(path, newBytes); + } + + return configuration; + } + } /// <summary> /// Reads an xml configuration file from the file system |
