diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs index d4b93cfb3..94d3fcbcb 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs @@ -1095,7 +1095,13 @@ public async Task WriteTokenDirect_BadValueAsync() { await jsonWriter.WriteTokenAsync(JsonToken.StartArray); - await ExceptionAssert.ThrowsAsync(async () => { await jsonWriter.WriteTokenAsync(JsonToken.Integer, "three"); }, "Input string was not in a correct format."); +#if NET7_0_OR_GREATER + // .NET 7.0 prints actual input in the message: + string expectedMessage = "The input string 'three' was not in a correct format."; +#else + string expectedMessage = "Input string was not in a correct format."; +#endif + await ExceptionAssert.ThrowsAsync(async () => { await jsonWriter.WriteTokenAsync(JsonToken.Integer, "three"); }, expectedMessage); await ExceptionAssert.ThrowsAsync(async () => { await jsonWriter.WriteTokenAsync(JsonToken.Integer); }, @"Value cannot be null. Parameter name: value", "Value cannot be null. (Parameter 'value')"); diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs index dcab597d8..75e67dc4f 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs @@ -966,7 +966,13 @@ public void WriteTokenDirect_BadValue() { jsonWriter.WriteToken(JsonToken.StartArray); - ExceptionAssert.Throws(() => { jsonWriter.WriteToken(JsonToken.Integer, "three"); }, "Input string was not in a correct format."); +#if NET7_0_OR_GREATER + // .NET 7.0 prints actual input in the message: + string expectedMessage = "The input string 'three' was not in a correct format."; +#else + string expectedMessage = "Input string was not in a correct format."; +#endif + ExceptionAssert.Throws(() => { jsonWriter.WriteToken(JsonToken.Integer, "three"); }, expectedMessage); ExceptionAssert.Throws(() => { jsonWriter.WriteToken(JsonToken.Integer); }, @"Value cannot be null. Parameter name: value", "Value cannot be null. (Parameter 'value')");