From 683502726e29ec7f6552bc66e95ae430e3f96a99 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Tue, 13 Aug 2024 19:56:18 +0100 Subject: [PATCH 1/9] Refactor JSON serialization to use MemoryStream Replaced StringWriter with MemoryStream and StreamWriter for JSON serialization to improve efficiency. JsonWriter is now initialized with StreamWriter. Adjusted indentation levels in ProcessStructure and ProcessMembers methods. Final request content is now obtained as a byte array from MemoryStream. --- .../Marshallers/JsonRPCRequestMarshaller.tt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt index e671d1a0dffc..719a7179a691 100644 --- a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt +++ b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt @@ -93,32 +93,35 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations if (this.Operation.RequestHasBodyMembers || shouldMarshallPayload) { #> - using (StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture)) - { - JsonWriter writer = new JsonWriter(stringWriter); - writer.Validate = false; + using (MemoryStream memoryStream = new MemoryStream()) + { + using (SreamWriter sreamWriter = new SreamWriter(memoryStream, null, -1, true)) + { + JsonWriter writer = new JsonWriter(sreamWriter); + writer.Validate = false; <# if (shouldMarshallPayload) { #> - var context = new JsonMarshallerContext(request, writer); + var context = new JsonMarshallerContext(request, writer); <# - ProcessStructure(0, "publicRequest." + payload.PropertyName, payload.Shape); + ProcessStructure(1, "publicRequest." + payload.PropertyName, payload.Shape); } else { #> - writer.WriteObjectStart(); - var context = new JsonMarshallerContext(request, writer); + writer.WriteObjectStart(); + var context = new JsonMarshallerContext(request, writer); <# - ProcessMembers(1, "publicRequest", this.Operation.RequestBodyMembers); + ProcessMembers(2, "publicRequest", this.Operation.RequestBodyMembers); #> - writer.WriteObjectEnd(); + writer.WriteObjectEnd(); <# } #> - string snippet = stringWriter.ToString(); - request.Content = System.Text.Encoding.UTF8.GetBytes(snippet); + } + + request.Content = memoryStream.ToArray(); <# GenerateRequestChecksumHandling(this.Operation, "snippet"); #> From c2319b23b30101ffb425ea69a57c683f699a5fe6 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:30:51 +0100 Subject: [PATCH 2/9] Update generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt Co-authored-by: Stuart Lang --- .../Generators/Marshallers/JsonRPCRequestMarshaller.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt index 719a7179a691..33d8624061ba 100644 --- a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt +++ b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt @@ -95,7 +95,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations #> using (MemoryStream memoryStream = new MemoryStream()) { - using (SreamWriter sreamWriter = new SreamWriter(memoryStream, null, -1, true)) + using (StreamWriter streamWriter = new StreamWriter(memoryStream, null, -1, true)) { JsonWriter writer = new JsonWriter(sreamWriter); writer.Validate = false; From fee28330102dddf13d827fd1b9d514885fcb721d Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Fri, 16 Aug 2024 08:31:01 +0100 Subject: [PATCH 3/9] Update generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt Co-authored-by: Stuart Lang --- .../Generators/Marshallers/JsonRPCRequestMarshaller.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt index 33d8624061ba..58734d48595d 100644 --- a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt +++ b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt @@ -97,7 +97,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations { using (StreamWriter streamWriter = new StreamWriter(memoryStream, null, -1, true)) { - JsonWriter writer = new JsonWriter(sreamWriter); + JsonWriter writer = new JsonWriter(streamWriter); writer.Validate = false; <# if (shouldMarshallPayload) From 7da96841725a8f8058ffd8c9b4945022c37a66cc Mon Sep 17 00:00:00 2001 From: aws-sdk-dotnet-automation Date: Thu, 15 Aug 2024 15:59:34 +0000 Subject: [PATCH 4/9] Commit version number update changes --- changelogs/SDK.CHANGELOG.2024.md | 5 +++++ changelogs/SDK.CHANGELOG.ALL.md | 5 +++++ .../525da348-b9e8-4f4d-9dc7-47b2ee7f4716.json | 9 --------- generator/ServiceModels/_sdk-versions.json | 4 ++-- 4 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 generator/.DevConfigs/525da348-b9e8-4f4d-9dc7-47b2ee7f4716.json diff --git a/changelogs/SDK.CHANGELOG.2024.md b/changelogs/SDK.CHANGELOG.2024.md index 1fb04988005c..31e00f66d21a 100644 --- a/changelogs/SDK.CHANGELOG.2024.md +++ b/changelogs/SDK.CHANGELOG.2024.md @@ -1,3 +1,8 @@ +### 4.0.0.0-preview (2024-08-15 14:46 UTC) +* Core 4.0.0.0 + * 4.0.0.0 Preview Release + * All services packages updated to require new Core + ### 3.7.857.0 (2024-08-02 18:27 UTC) * CloudWatch (3.7.401.0) * Add v2 smoke tests and smithy smokeTests trait for SDK testing. diff --git a/changelogs/SDK.CHANGELOG.ALL.md b/changelogs/SDK.CHANGELOG.ALL.md index 457aea58f87a..754bd097115f 100644 --- a/changelogs/SDK.CHANGELOG.ALL.md +++ b/changelogs/SDK.CHANGELOG.ALL.md @@ -1,3 +1,8 @@ +### 4.0.0.0-preview (2024-08-15 14:46 UTC) +* Core 4.0.0.0 + * 4.0.0.0 Preview Release + * All services packages updated to require new Core + ### 3.7.857.0 (2024-08-02 18:27 UTC) * CloudWatch (3.7.401.0) * Add v2 smoke tests and smithy smokeTests trait for SDK testing. diff --git a/generator/.DevConfigs/525da348-b9e8-4f4d-9dc7-47b2ee7f4716.json b/generator/.DevConfigs/525da348-b9e8-4f4d-9dc7-47b2ee7f4716.json deleted file mode 100644 index 77aee8feb507..000000000000 --- a/generator/.DevConfigs/525da348-b9e8-4f4d-9dc7-47b2ee7f4716.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "core": { - "updateMinimum": true, - "changeLogMessages": [ - "4.0.0.0 Preview Release" - ] - }, - "overrideVersion": "4.0.0.0" -} \ No newline at end of file diff --git a/generator/ServiceModels/_sdk-versions.json b/generator/ServiceModels/_sdk-versions.json index 13efdd460eed..7424355d7e60 100644 --- a/generator/ServiceModels/_sdk-versions.json +++ b/generator/ServiceModels/_sdk-versions.json @@ -6,7 +6,6 @@ "OverrideCoreVersion" : "4.0", "DefaultToPreview" : true, "PreviewLabel" : "preview", - "DefaultAssemblyVersion" : "4.0", "ServiceVersions" : { "CloudHSM" : { "Version" : "4.0.0.0", @@ -3100,5 +3099,6 @@ }, "InPreview" : false } - } + }, + "DefaultAssemblyVersion" : "4.0" } \ No newline at end of file From 5a40b4658cd2e9d1b7dd5cc1a3bf928ade9d1f33 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Mon, 5 Aug 2024 19:23:50 +0100 Subject: [PATCH 5/9] Refactor User-Agent construction in Marshaller.cs Updated `SetUserAgentHeader` to improve User-Agent string construction: - Initialize `StringBuilder` with a capacity of 256. - Append `UserAgent` after replacing invalid characters. - Append `ClientAppId` after replacing invalid characters. - Use `ToUserAgentHeaderString` for retry mode conversion. - Append `IsAsync` and initialization config directly. - Append `UserAgentAddition` after replacing invalid characters. - Removed redundant call to `ReplaceInvalidUserAgentCharacters`. - Added `ToUserAgentHeaderString` method for `RequestRetryMode`. --- .../Pipeline/Handlers/Marshaller.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs index 839d09fd4173..182c0767529f 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs @@ -106,29 +106,28 @@ private static void SetRecursionDetectionHeader(IDictionary head private static void SetUserAgentHeader(IRequestContext requestContext) { - var sb = new StringBuilder(requestContext.ClientConfig.UserAgent); + var sb = new StringBuilder(256); + + sb.Append(InternalSDKUtils.ReplaceInvalidUserAgentCharacters(requestContext.ClientConfig.UserAgent)); var clientAppId = requestContext.ClientConfig.ClientAppId; if (!string.IsNullOrEmpty(clientAppId)) - sb.AppendFormat(" app/{0}", clientAppId); + sb.Append(" app/").Append(InternalSDKUtils.ReplaceInvalidUserAgentCharacters(clientAppId)); - var retryMode = requestContext.ClientConfig.RetryMode.ToString().ToLower(); - sb.AppendFormat(" cfg/retry-mode#{0}", retryMode); + sb.Append(" cfg/retry-mode#}").Append(ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode)); - sb.AppendFormat(" md/{0}", requestContext.IsAsync ? "ClientAsync" : "ClientSync"); + sb.Append(" md/").Append(IsAsync ? "ClientAsync" : "ClientSync"); - sb.AppendFormat(" cfg/init-coll#{0}", AWSConfigs.InitializeCollections ? "1" : "0"); + sb.Append(" cfg/init-coll#").Append(InitializeCollections ? '1' : '0'); var userAgentAddition = requestContext.OriginalRequest.UserAgentAddition; if (!string.IsNullOrEmpty(userAgentAddition)) { - sb.AppendFormat(" {0}", userAgentAddition); + sb.Append(' ').Append(InternalSDKUtils.ReplaceInvalidUserAgentCharacters(userAgentAddition)); } var userAgent = sb.ToString(); - userAgent = InternalSDKUtils.ReplaceInvalidUserAgentCharacters(userAgent); - if (requestContext.ClientConfig.UseAlternateUserAgentHeader) { requestContext.Request.Headers[HeaderKeys.XAmzUserAgentHeader] = userAgent; @@ -138,5 +137,13 @@ private static void SetUserAgentHeader(IRequestContext requestContext) requestContext.Request.Headers[HeaderKeys.UserAgentHeader] = userAgent; } } + + private static string ToUserAgentHeaderString(RequestRetryMode requestRetryMode) + { + if (requestRetryMode == RequestRetryMode.Adaptive) + return "adaptive"; + else + return "standard"; + } } } From b15a8f5863a6f245e9c2fe2bbc6d97b7e2454d45 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:54:05 +0100 Subject: [PATCH 6/9] Improve user agent string construction in Marshaller.cs Added a `using System.Diagnostics;` directive. Introduced a `retryMode` variable and added a `Debug.Assert` to ensure its correctness. Updated user agent string logic to use `retryMode` and `requestContext.IsAsync`. Changed initialization collections flag to `AWSConfigs.InitializeCollections`. --- .../Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs index 182c0767529f..6ead057028a8 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs @@ -15,6 +15,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.Text; using Amazon.Runtime.Telemetry; @@ -114,11 +115,13 @@ private static void SetUserAgentHeader(IRequestContext requestContext) if (!string.IsNullOrEmpty(clientAppId)) sb.Append(" app/").Append(InternalSDKUtils.ReplaceInvalidUserAgentCharacters(clientAppId)); - sb.Append(" cfg/retry-mode#}").Append(ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode)); + var retryMode = ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode); + Debug.Assert(retryMode != requestContext.ClientConfig.RetryMode.ToString().ToLower(), "Invalid RetryMode string."); + sb.Append(" cfg/retry-mode#}").Append(retryMode); - sb.Append(" md/").Append(IsAsync ? "ClientAsync" : "ClientSync"); + sb.Append(" md/").Append(requestContext.IsAsync ? "ClientAsync" : "ClientSync"); - sb.Append(" cfg/init-coll#").Append(InitializeCollections ? '1' : '0'); + sb.Append(" cfg/init-coll#").Append(AWSConfigs.InitializeCollections ? '1' : '0'); var userAgentAddition = requestContext.OriginalRequest.UserAgentAddition; if (!string.IsNullOrEmpty(userAgentAddition)) From ee5d785b26148ee1956d071c6f91c1ab2e2e6400 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:41:29 +0100 Subject: [PATCH 7/9] Refactor ToUserAgentHeaderString and add new test Refactored the ToUserAgentHeaderString method in Marshaller.cs to use a switch statement instead of if-else statements, including a default case for converting requestRetryMode to lowercase. Removed Debug.Assert for retryMode and directly appended it to the StringBuilder object. Added LookForRequestRetryModeChanges test in StaticCheckTests.cs to verify the integrity of the RequestRetryMode enum. --- .../Pipeline/Handlers/Marshaller.cs | 17 ++++++++++------- .../UnitTests/Custom/StaticCheckTests.cs | 10 ++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs b/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs index 6ead057028a8..3b7fc0315665 100644 --- a/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs +++ b/sdk/src/Core/Amazon.Runtime/Pipeline/Handlers/Marshaller.cs @@ -115,9 +115,7 @@ private static void SetUserAgentHeader(IRequestContext requestContext) if (!string.IsNullOrEmpty(clientAppId)) sb.Append(" app/").Append(InternalSDKUtils.ReplaceInvalidUserAgentCharacters(clientAppId)); - var retryMode = ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode); - Debug.Assert(retryMode != requestContext.ClientConfig.RetryMode.ToString().ToLower(), "Invalid RetryMode string."); - sb.Append(" cfg/retry-mode#}").Append(retryMode); + sb.Append(" cfg/retry-mode#}").Append(ToUserAgentHeaderString(requestContext.ClientConfig.RetryMode)); sb.Append(" md/").Append(requestContext.IsAsync ? "ClientAsync" : "ClientSync"); @@ -143,10 +141,15 @@ private static void SetUserAgentHeader(IRequestContext requestContext) private static string ToUserAgentHeaderString(RequestRetryMode requestRetryMode) { - if (requestRetryMode == RequestRetryMode.Adaptive) - return "adaptive"; - else - return "standard"; + switch (requestRetryMode) + { + case RequestRetryMode.Standard: + return "standard"; + case RequestRetryMode.Adaptive: + return "adaptive"; + default: + return requestRetryMode.ToString().ToLowerInvariant(); + } } } } diff --git a/sdk/test/Services/SecurityToken/UnitTests/Custom/StaticCheckTests.cs b/sdk/test/Services/SecurityToken/UnitTests/Custom/StaticCheckTests.cs index 1f516a944cfd..1b576b6ae127 100644 --- a/sdk/test/Services/SecurityToken/UnitTests/Custom/StaticCheckTests.cs +++ b/sdk/test/Services/SecurityToken/UnitTests/Custom/StaticCheckTests.cs @@ -83,5 +83,15 @@ public void EnsureCredentialProfileDetectorSetup() // the properties are used at least once. Assert.IsTrue(profileOptionsProperties.SetEquals(referencedProfileOptionsProperties)); } + + [TestMethod] + public void LookForRequestRetryModeChanges() + { + var expectedHash = "2FC699DB6A4284C5D53F3B7FA4E64165576FD1F6AE458BC737AE503F06DFBE4C"; + AssertExtensions.AssertEnumUnchanged( + typeof(RequestRetryMode), + expectedHash, + "The Amazon.Runtime.Internal.Marshaller.ToUserAgentHeaderString method implementation may need to be updated."); + } } } \ No newline at end of file From 86ad7252712152a36b398058cbea4b621c7fa9e0 Mon Sep 17 00:00:00 2001 From: Muhammad Othman Date: Fri, 16 Aug 2024 09:51:29 -0400 Subject: [PATCH 8/9] Add devConfig and suppress NormalizeStringsToUppercase warning in ToUserAgentHeaderString --- .../aabf4e64-a7dd-4ee3-95a7-c8466c22a7e3.json | 9 +++++++++ sdk/src/Core/GlobalSuppressions.cs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 generator/.DevConfigs/aabf4e64-a7dd-4ee3-95a7-c8466c22a7e3.json diff --git a/generator/.DevConfigs/aabf4e64-a7dd-4ee3-95a7-c8466c22a7e3.json b/generator/.DevConfigs/aabf4e64-a7dd-4ee3-95a7-c8466c22a7e3.json new file mode 100644 index 000000000000..a0f861467e75 --- /dev/null +++ b/generator/.DevConfigs/aabf4e64-a7dd-4ee3-95a7-c8466c22a7e3.json @@ -0,0 +1,9 @@ +{ + "core": { + "changeLogMessages": [ + "Improve user agent string construction in Marshaller.cs" + ], + "type": "patch", + "updateMinimum": true + } +} \ No newline at end of file diff --git a/sdk/src/Core/GlobalSuppressions.cs b/sdk/src/Core/GlobalSuppressions.cs index 476b7e93d6d5..359bd1bc2926 100644 --- a/sdk/src/Core/GlobalSuppressions.cs +++ b/sdk/src/Core/GlobalSuppressions.cs @@ -191,9 +191,9 @@ [module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Amazon.Runtime.Internal.Auth.AWS4Signer.#CanonicalizeHeaders(System.Collections.Generic.ICollection`1>)")] [module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Amazon.Runtime.Internal.Auth.S3Signer.#BuildCanonicalizedHeaders(System.Collections.Generic.IDictionary`2)")] [module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Amazon.Runtime.Internal.Auth.AWS4Signer.#DetermineSigningRegion(Amazon.Runtime.IClientConfig,System.String,Amazon.RegionEndpoint,Amazon.Runtime.Internal.IRequest)")] - [module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Amazon.Runtime.Internal.Auth.AWS4Signer.#CanonicalizeHeaders(System.Collections.Generic.IDictionary`2)")] [module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Amazon.Runtime.Internal.Auth.AWS4Signer.#CanonicalizeHeaderNames(System.Collections.Generic.IDictionary`2)")] +[module: SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Scope = "member", Target = "Amazon.Runtime.Internal.Marshaller.#ToUserAgentHeaderString(Amazon.Runtime.RequestRetryMode)")] // Types names matching namespaces [module: SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces", Scope = "type", Target = "Amazon.Auth.AccessControlPolicy.Policy")] From 0d30ae522626f116b88d883cc897d78fc2529f56 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:44:37 +0100 Subject: [PATCH 9/9] Simplify StreamWriter instantiation Refactor the instantiation of the `StreamWriter` object within a `using` statement by removing unnecessary parameters. The original code included `null` for encoding, `-1` for buffer size, and `true` for leaving the stream open. The updated code uses the default constructor, which only requires the `MemoryStream` object, as the default behavior is sufficient for the intended use case. --- .../Generators/Marshallers/JsonRPCRequestMarshaller.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt index 58734d48595d..797bf962ad4d 100644 --- a/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt +++ b/generator/ServiceClientGeneratorLib/Generators/Marshallers/JsonRPCRequestMarshaller.tt @@ -95,7 +95,7 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations #> using (MemoryStream memoryStream = new MemoryStream()) { - using (StreamWriter streamWriter = new StreamWriter(memoryStream, null, -1, true)) + using (StreamWriter streamWriter = new StreamWriter(memoryStream)) { JsonWriter writer = new JsonWriter(streamWriter); writer.Validate = false;