Skip to content

Commit

Permalink
Fix for truncated streams in .NET 4.0 which does not have a leaveOpen…
Browse files Browse the repository at this point in the history
… option #157
  • Loading branch information
rianjs committed Oct 19, 2016
1 parent 4f85da5 commit 9b73f73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion v2/Ical.Net.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Ical.Net</id>
<version>2.2.14</version>
<version>2.2.15</version>
<title>Ical.Net</title>
<authors>Rian Stockbower, Douglas Day, M. David Peterson</authors>
<owners>Rian Stockbower</owners>
Expand Down
26 changes: 12 additions & 14 deletions v2/ical.NET/Serialization/iCalendar/Serializers/SerializerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,22 @@ public void Serialize(object obj, Stream stream, Encoding encoding)
// we don't want the stream to be closed by this serialization.
// Fixes bug #3177278 - Serialize closes stream

const int defaultBuffer = 1024; //This is StreamWriter's built-in default buffer size
using (var sw = new StreamWriter(stream, encoding, defaultBuffer, leaveOpen: true))
{
// Push the current object onto the serialization stack
SerializationContext.Push(obj);
var sw = new StreamWriter(stream, encoding);
// Push the current object onto the serialization stack
SerializationContext.Push(obj);

// Push the current encoding on the stack
var encodingStack = GetService<EncodingStack>();
encodingStack.Push(encoding);
// Push the current encoding on the stack
var encodingStack = GetService<EncodingStack>();
encodingStack.Push(encoding);

sw.Write(SerializeToString(obj));
sw.Write(SerializeToString(obj));

// Pop the current encoding off the serialization stack
encodingStack.Pop();
// Pop the current encoding off the serialization stack
encodingStack.Pop();

// Pop the current object off the serialization stack
SerializationContext.Pop();
}
// Pop the current object off the serialization stack
SerializationContext.Pop();
sw.Flush();
}

public virtual object GetService(Type serviceType)
Expand Down

0 comments on commit 9b73f73

Please sign in to comment.