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

JSONEncoder should use Stream, support leaveOpen on close #1444

Closed
1 task done
mregen opened this issue Jul 6, 2021 · 1 comment · Fixed by #1448
Closed
1 task done

JSONEncoder should use Stream, support leaveOpen on close #1444

mregen opened this issue Jul 6, 2021 · 1 comment · Fixed by #1448
Assignees

Comments

@mregen
Copy link
Contributor

mregen commented Jul 6, 2021

Type of Issue

  • Bug

Describe the Issue

Constructor allows external StreamWriter to use:

public JsonEncoder(
            IServiceMessageContext context,
            bool useReversibleEncoding,
            StreamWriter writer = null,
            bool topLevelIsArray = false)

, but the Streamwriter is disposed in Close.

--> Update: use Stream and leaveopen in the signature, mark this constructor as obsolete
--> for back compat leave dispose in close, but support leaveOpen for external stream.

To Reproduce

use ext.StreamWriter, try to reuse Streamwriter after encoding, need to create a new StreamWriter, but disposed object cannot be reused.

Expected behavior

external Streamwriter is not disposed, only internal.

Code snippets

            m_writer.Dispose();  // only dispose if streamwriter is owned by JSONEncoder.
            m_writer = null;
            return length;

Environment (please complete the following information):

  • OS: any
  • Development environment: Visual Studio 2019
  • Runtime: .NET Core 3.1
  • Component: JSONEncoder, Core
@mregen
Copy link
Contributor Author

mregen commented Jul 8, 2021

some more issues found while working on #1448 👍🏼

-constructor signature of encoders should allow for similar use..
-use Stream instead of Streamwriter in constructor

@mregen mregen changed the title JSONEncoder should not dispose external Streamwriter on close JSONEncoder should use Stream, support leaveOpen on close Jul 8, 2021
@mregen mregen self-assigned this Jul 8, 2021
mregen added a commit that referenced this issue Jul 9, 2021
- only dispose StreamWriter if owned by JsonEncoder
- only dispose if dispose is called
- on external stream writer, return text by using reflection on basestream, if memorystream is used
- improve benchmark common code
- fixes #1444
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

Successfully merging a pull request may close this issue.

1 participant