Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerializerBase.Serialize produces truncated string #157

Closed
mcshaz opened this issue Oct 5, 2016 · 3 comments
Closed

SerializerBase.Serialize produces truncated string #157

mcshaz opened this issue Oct 5, 2016 · 3 comments

Comments

@mcshaz
Copy link
Contributor

mcshaz commented Oct 5, 2016

SerializerBase has the code:

public void Serialize(object obj, Stream stream, Encoding encoding)
{
        // NOTE: we don't use a 'using' statement here because
        // we don't want the stream to be closed by this serialization.
       // Fixes bug #3177278 - Serialize closes stream
       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<IEncodingStack>();
       encodingStack.Push(encoding);
       sw.Write(SerializeToString(obj));
       // Pop the current encoding off the serialization stack
       encodingStack.Pop();
       // Pop the current object off the serialization stack
      SerializationContext.Pop();
}

This is resulting in the stream having a truncated string written to it if that string is bigger than the default buffer size.

the 2 options are:

  1. call sw.Flush() after sw.Write();
  2. wrap the StreamWriter in a using block but use the overload StreamWriter(Stream stream, Encoding encoding, int bufferSize, bool leaveOpen) & set leaveOpen to true
@rianjs
Copy link
Collaborator

rianjs commented Oct 18, 2016

ae6f95d

@rianjs rianjs closed this as completed Oct 18, 2016
rianjs added a commit that referenced this issue Oct 18, 2016
rianjs added a commit that referenced this issue Oct 18, 2016
@rianjs
Copy link
Collaborator

rianjs commented Oct 19, 2016

Naturally .NET 4.0 doesn't have a leaveOpen constructor parameter for streams.

I really should just leave .NET 4.0 behind. Supporting it is way more terrible than it should be.

@rianjs rianjs reopened this Oct 19, 2016
rianjs added a commit that referenced this issue Oct 19, 2016
Fix for truncated streams in .NET 4.0 which does not have a leaveOpen option #157
@rianjs
Copy link
Collaborator

rianjs commented Oct 19, 2016

Fix published in Nuget package 2.2.15

@rianjs rianjs closed this as completed Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants