From a222c8b69cc8ae55d938339362c2550c939a1e4d Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 20 Nov 2020 16:35:24 +1300 Subject: [PATCH] Update to net50 and fix warnings (#2424) --- Build/build.ps1 | 14 +++++++++---- Src/Directory.Build.props | 2 +- .../Newtonsoft.Json.TestConsole.csproj | 2 +- Src/Newtonsoft.Json.Tests/ExceptionTests.cs | 2 ++ .../JsonTextReaderTests/ParseAsyncTests.cs | 4 ++-- .../JsonTextReaderTests/ParseTests.cs | 4 ++-- .../JsonTextWriterAsyncTests.cs | 2 +- .../JsonTextWriterTest.cs | 2 +- .../Newtonsoft.Json.Tests.csproj | 12 +++++------ .../JsonSerializerCollectionsTests.cs | 2 +- .../Serialization/JsonSerializerTest.cs | 20 ++++++++++++++++-- Src/Newtonsoft.Json/JsonConvert.cs | 12 +++++------ Src/Newtonsoft.Json/JsonConverter.cs | 4 ++-- Src/Newtonsoft.Json/JsonSerializer.cs | 3 +-- Src/Newtonsoft.Json/Linq/Extensions.cs | 21 +++++++++---------- Src/Newtonsoft.Json/Linq/JContainer.cs | 4 ++-- Src/Newtonsoft.Json/Linq/JEnumerable.cs | 2 +- Src/Newtonsoft.Json/Linq/JToken.cs | 10 ++++----- Src/Newtonsoft.Json/Linq/JValue.cs | 2 +- Src/Newtonsoft.Json/Newtonsoft.Json.csproj | 2 +- .../JsonSerializerInternalReader.cs | 2 +- .../JsonSerializerInternalWriter.cs | 8 ++++--- Src/Newtonsoft.Json/Utilities/AsyncUtils.cs | 4 ++-- .../Utilities/DictionaryWrapper.cs | 4 +++- .../Utilities/JavaScriptUtils.cs | 2 +- Src/global.json | 2 +- azure-pipelines.yml | 2 +- 27 files changed, 86 insertions(+), 64 deletions(-) diff --git a/Build/build.ps1 b/Build/build.ps1 index 696e58ed..76b805b1 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -14,8 +14,9 @@ $workingName = if ($workingName) {$workingName} else {"Working"} $assemblyVersion = if ($assemblyVersion) {$assemblyVersion} else {$majorVersion + '.0.0'} $netCliChannel = "Current" - $netCliVersion = "3.0.100" + $netCliVersion = "5.0.100" $nugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" + $ensureNetCliSdk = $true $baseDir = resolve-path .. $buildDir = "$baseDir\Build" @@ -31,8 +32,8 @@ $nunitConsolePath = "$buildDir\Temp\NUnit.ConsoleRunner.$nunitConsoleVersion" $builds = @( - @{Framework = "netstandard2.0"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp3.0"; Enabled=$true}, - @{Framework = "netstandard1.3"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp2.2"; Enabled=$true}, + @{Framework = "netstandard2.0"; TestsFunction = "NetCliTests"; TestFramework = "net5.0"; Enabled=$true}, + @{Framework = "netstandard1.3"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp3.1"; Enabled=$true}, @{Framework = "netstandard1.0"; TestsFunction = "NetCliTests"; TestFramework = "netcoreapp2.1"; Enabled=$true}, @{Framework = "net45"; TestsFunction = "NUnitTests"; TestFramework = "net46"; NUnitFramework="net-4.0"; Enabled=$true}, @{Framework = "net40"; TestsFunction = "NUnitTests"; NUnitFramework="net-4.0"; Enabled=$true}, @@ -69,7 +70,10 @@ task Build -depends Clean { mkdir "$buildDir\Temp" -Force - EnsureDotNetCli + if ($ensureNetCliSdk) + { + EnsureDotNetCli + } EnsureNuGetExists EnsureNuGetPackage "vswhere" $vswherePath $vswhereVersion EnsureNuGetPackage "NUnit.ConsoleRunner" $nunitConsolePath $nunitConsoleVersion @@ -170,6 +174,8 @@ function EnsureDotnetCli() -OutFile "$buildDir\Temp\dotnet-install.ps1" exec { & $buildDir\Temp\dotnet-install.ps1 -Channel $netCliChannel -Version $netCliVersion | Out-Default } + exec { & $buildDir\Temp\dotnet-install.ps1 -Channel $netCliChannel -Version '3.1.402' | Out-Default } + exec { & $buildDir\Temp\dotnet-install.ps1 -Channel $netCliChannel -Version '2.1.811' | Out-Default } } function EnsureNuGetExists() diff --git a/Src/Directory.Build.props b/Src/Directory.Build.props index 246b9ba6..11ecc418 100644 --- a/Src/Directory.Build.props +++ b/Src/Directory.Build.props @@ -6,7 +6,7 @@ 2.9.2 4.3.0 1.0.0-beta2-19367-01 - 3.3.1 + 3.8.0 16.3.0 4.8.1 3.11.0 diff --git a/Src/Newtonsoft.Json.TestConsole/Newtonsoft.Json.TestConsole.csproj b/Src/Newtonsoft.Json.TestConsole/Newtonsoft.Json.TestConsole.csproj index a60bfbca..5959077a 100644 --- a/Src/Newtonsoft.Json.TestConsole/Newtonsoft.Json.TestConsole.csproj +++ b/Src/Newtonsoft.Json.TestConsole/Newtonsoft.Json.TestConsole.csproj @@ -1,7 +1,7 @@  Exe - net46;netcoreapp3.0 + net46;net5.0 latest Newtonsoft.Json.TestConsole Newtonsoft.Json.TestConsole diff --git a/Src/Newtonsoft.Json.Tests/ExceptionTests.cs b/Src/Newtonsoft.Json.Tests/ExceptionTests.cs index ce93ecd0..ff0b1148 100644 --- a/Src/Newtonsoft.Json.Tests/ExceptionTests.cs +++ b/Src/Newtonsoft.Json.Tests/ExceptionTests.cs @@ -113,7 +113,9 @@ namespace Newtonsoft.Json.Tests using (var memoryStream = new MemoryStream()) { var binaryFormatter = new BinaryFormatter(); +#pragma warning disable SYSLIB0011 // Type or member is obsolete binaryFormatter.Serialize(memoryStream, exception); +#pragma warning restore SYSLIB0011 // Type or member is obsolete } } #endif diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseAsyncTests.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseAsyncTests.cs index 09e2aab2..2d61a6b9 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseAsyncTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseAsyncTests.cs @@ -200,7 +200,7 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests Assert.AreEqual(Double.MinValue, reader.Value); reader = new JsonTextReader(new StringReader("1E+309")); -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) await ExceptionAssert.ThrowsAsync(async () => await reader.ReadAsync(), "Input string '1E+309' is not a valid number. Path '', line 1, position 6."); #else Assert.IsTrue(await reader.ReadAsync()); @@ -209,7 +209,7 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests #endif reader = new JsonTextReader(new StringReader("-1E+5000")); -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) await ExceptionAssert.ThrowsAsync(async () => await reader.ReadAsync(), "Input string '-1E+5000' is not a valid number. Path '', line 1, position 8."); #else Assert.IsTrue(await reader.ReadAsync()); diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseTests.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseTests.cs index aff080da..0347a2ad 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTests/ParseTests.cs @@ -220,7 +220,7 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests Assert.AreEqual(Double.MinValue, reader.Value); reader = new JsonTextReader(new StringReader("1E+309")); -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) ExceptionAssert.Throws(() => reader.Read(), "Input string '1E+309' is not a valid number. Path '', line 1, position 6."); #else Assert.IsTrue(reader.Read()); @@ -229,7 +229,7 @@ namespace Newtonsoft.Json.Tests.JsonTextReaderTests #endif reader = new JsonTextReader(new StringReader("-1E+5000")); -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) ExceptionAssert.Throws(() => reader.Read(), "Input string '-1E+5000' is not a valid number. Path '', line 1, position 8."); #else Assert.IsTrue(reader.Read()); diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs index 56d9b8c8..f61d7e5e 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterAsyncTests.cs @@ -1018,7 +1018,7 @@ namespace Newtonsoft.Json.Tests await jsonWriter.WriteEndArrayAsync(); } -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) Assert.AreEqual(@"[0.0,0.0,0.1,1.0,1.000001,1E-06,4.94065645841247E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN]", sb.ToString()); #else Assert.AreEqual(@"[0.0,0.0,0.1,1.0,1.000001,1E-06,5E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN]", sb.ToString()); diff --git a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs index d463ddc3..2652f9f2 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextWriterTest.cs @@ -880,7 +880,7 @@ namespace Newtonsoft.Json.Tests jsonWriter.WriteEndArray(); } -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) Assert.AreEqual(@"[0.0,0.0,0.1,1.0,1.000001,1E-06,4.94065645841247E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN]", sb.ToString()); #else Assert.AreEqual(@"[0.0,0.0,0.1,1.0,1.000001,1E-06,5E-324,Infinity,-Infinity,NaN,1.7976931348623157E+308,-1.7976931348623157E+308,Infinity,-Infinity,NaN]", sb.ToString()); diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj index cd4c9a39..2d619e32 100644 --- a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.csproj @@ -1,6 +1,6 @@  - net46;net40;net35;net20;netcoreapp3.0;netcoreapp2.2;netcoreapp2.1 + net46;net40;net35;net20;net5.0;netcoreapp3.1;netcoreapp2.1 $(TestFrameworks) 8.0 1.0 @@ -13,7 +13,7 @@ Newtonsoft.Json.Tests false - Full + Full false @@ -107,7 +107,7 @@ NET20;$(AdditionalConstants) - + @@ -122,13 +122,13 @@ - + Json.NET Tests .NET Standard 2.0 .NETStandard,Version=v2.0 NETSTANDARD2_0;DNXCORE50;PORTABLE;HAVE_BENCHMARKS;$(AdditionalConstants) - + @@ -143,7 +143,7 @@ - + Json.NET Tests .NET Standard 1.3 .NETStandard,Version=v1.3 NETSTANDARD1_3;DNXCORE50;PORTABLE;HAVE_BENCHMARKS;$(AdditionalConstants) diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs index 631cd6ec..ab790c4b 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerCollectionsTests.cs @@ -187,7 +187,7 @@ namespace Newtonsoft.Json.Tests.Serialization { Dictionary dictionary = new Dictionary { { float.MaxValue, 1 } }; string output = JsonConvert.SerializeObject(dictionary); -#if !NETSTANDARD2_0 +#if !(NETSTANDARD2_0 || NETSTANDARD1_3) Assert.AreEqual(@"{""3.40282347E+38"":1}", output); #else Assert.AreEqual(@"{""3.4028235E+38"":1}", output); diff --git a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs index 26190d2f..12a7137a 100644 --- a/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs @@ -2258,7 +2258,7 @@ keyword such as type of business."" string json = JsonConvert.SerializeObject(new ConverableMembers(), Formatting.Indented); string expected = null; -#if NETSTANDARD2_0 +#if (NETSTANDARD2_0) expected = @"{ ""String"": ""string"", ""Int32"": 2147483647, @@ -2275,7 +2275,23 @@ keyword such as type of business."" ""Bool"": true, ""Char"": ""\u0000"" }"; -#elif !(PORTABLE || DNXCORE50) +#elif NETSTANDARD1_3 + expected = @"{ + ""String"": ""string"", + ""Int32"": 2147483647, + ""UInt32"": 4294967295, + ""Byte"": 255, + ""SByte"": 127, + ""Short"": 32767, + ""UShort"": 65535, + ""Long"": 9223372036854775807, + ""ULong"": 9223372036854775807, + ""Double"": 1.7976931348623157E+308, + ""Float"": 3.4028235E+38, + ""Bool"": true, + ""Char"": ""\u0000"" +}"; +#elif !(PORTABLE || DNXCORE50) || NETSTANDARD1_3 expected = @"{ ""String"": ""string"", ""Int32"": 2147483647, diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs index 22a4f627..a8d7a1a5 100644 --- a/Src/Newtonsoft.Json/JsonConvert.cs +++ b/Src/Newtonsoft.Json/JsonConvert.cs @@ -715,7 +715,7 @@ namespace Newtonsoft.Json /// The JSON to deserialize. /// The deserialized object from the JSON string. [DebuggerStepThrough] - public static T DeserializeObject(string value) + public static T? DeserializeObject(string value) { return DeserializeObject(value, (JsonSerializerSettings?)null); } @@ -732,7 +732,7 @@ namespace Newtonsoft.Json /// The anonymous type object. /// The deserialized anonymous type from the JSON string. [DebuggerStepThrough] - public static T DeserializeAnonymousType(string value, T anonymousTypeObject) + public static T? DeserializeAnonymousType(string value, T anonymousTypeObject) { return DeserializeObject(value); } @@ -753,7 +753,7 @@ namespace Newtonsoft.Json /// /// The deserialized anonymous type from the JSON string. [DebuggerStepThrough] - public static T DeserializeAnonymousType(string value, T anonymousTypeObject, JsonSerializerSettings settings) + public static T? DeserializeAnonymousType(string value, T anonymousTypeObject, JsonSerializerSettings settings) { return DeserializeObject(value, settings); } @@ -766,8 +766,7 @@ namespace Newtonsoft.Json /// Converters to use while deserializing. /// The deserialized object from the JSON string. [DebuggerStepThrough] - [return: MaybeNull] - public static T DeserializeObject(string value, params JsonConverter[] converters) + public static T? DeserializeObject(string value, params JsonConverter[] converters) { #pragma warning disable CS8601 // Possible null reference assignment. return (T)DeserializeObject(value, typeof(T), converters); @@ -785,8 +784,7 @@ namespace Newtonsoft.Json /// /// The deserialized object from the JSON string. [DebuggerStepThrough] - [return: MaybeNull] - public static T DeserializeObject(string value, JsonSerializerSettings? settings) + public static T? DeserializeObject(string value, JsonSerializerSettings? settings) { #pragma warning disable CS8601 // Possible null reference assignment. return (T)DeserializeObject(value, typeof(T), settings); diff --git a/Src/Newtonsoft.Json/JsonConverter.cs b/Src/Newtonsoft.Json/JsonConverter.cs index 5e75103e..6b8a1ca2 100644 --- a/Src/Newtonsoft.Json/JsonConverter.cs +++ b/Src/Newtonsoft.Json/JsonConverter.cs @@ -105,7 +105,7 @@ namespace Newtonsoft.Json /// The to write to. /// The value. /// The calling serializer. - public abstract void WriteJson(JsonWriter writer, [AllowNull]T value, JsonSerializer serializer); + public abstract void WriteJson(JsonWriter writer, T? value, JsonSerializer serializer); /// /// Reads the JSON representation of the object. @@ -136,7 +136,7 @@ namespace Newtonsoft.Json /// The existing value has a value. /// The calling serializer. /// The object value. - public abstract T ReadJson(JsonReader reader, Type objectType, [AllowNull]T existingValue, bool hasExistingValue, JsonSerializer serializer); + public abstract T? ReadJson(JsonReader reader, Type objectType, T? existingValue, bool hasExistingValue, JsonSerializer serializer); /// /// Determines whether this instance can convert the specified object type. diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index 2544595c..241ec06d 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -865,8 +865,7 @@ namespace Newtonsoft.Json /// The type of the object to deserialize. /// The instance of being deserialized. [DebuggerStepThrough] - [return: MaybeNull] - public T Deserialize(JsonReader reader) + public T? Deserialize(JsonReader reader) { #pragma warning disable CS8601 // Possible null reference assignment. return (T)Deserialize(reader, typeof(T)); diff --git a/Src/Newtonsoft.Json/Linq/Extensions.cs b/Src/Newtonsoft.Json/Linq/Extensions.cs index da19f8a2..e05fd262 100644 --- a/Src/Newtonsoft.Json/Linq/Extensions.cs +++ b/Src/Newtonsoft.Json/Linq/Extensions.cs @@ -115,7 +115,7 @@ namespace Newtonsoft.Json.Linq /// An of that contains the values of every token in the source collection with the given key. public static IJEnumerable Values(this IEnumerable source, object? key) { - return Values(source, key).AsJEnumerable(); + return Values(source, key)!.AsJEnumerable(); } /// @@ -135,7 +135,7 @@ namespace Newtonsoft.Json.Linq /// An of that contains the source collection. /// The token key. /// An that contains the converted values of every token in the source collection with the given key. - public static IEnumerable Values(this IEnumerable source, object key) + public static IEnumerable Values(this IEnumerable source, object key) { return Values(source, key); } @@ -146,7 +146,7 @@ namespace Newtonsoft.Json.Linq /// The type to convert the values to. /// An of that contains the source collection. /// An that contains the converted values of every token in the source collection. - public static IEnumerable Values(this IEnumerable source) + public static IEnumerable Values(this IEnumerable source) { return Values(source, null); } @@ -157,7 +157,7 @@ namespace Newtonsoft.Json.Linq /// The type to convert the value to. /// A cast as a of . /// A converted value. - public static U Value(this IEnumerable value) + public static U? Value(this IEnumerable value) { return value.Value(); } @@ -169,7 +169,7 @@ namespace Newtonsoft.Json.Linq /// The type to convert the value to. /// A cast as a of . /// A converted value. - public static U Value(this IEnumerable value) where T : JToken + public static U? Value(this IEnumerable value) where T : JToken { ValidationUtils.ArgumentNotNull(value, nameof(value)); @@ -181,7 +181,7 @@ namespace Newtonsoft.Json.Linq return token.Convert(); } - internal static IEnumerable Values(this IEnumerable source, object? key) where T : JToken + internal static IEnumerable Values(this IEnumerable source, object? key) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); @@ -226,7 +226,7 @@ namespace Newtonsoft.Json.Linq /// An of that contains the values of every token in the source collection. public static IJEnumerable Children(this IEnumerable source) where T : JToken { - return Children(source).AsJEnumerable(); + return Children(source)!.AsJEnumerable(); } /// @@ -236,14 +236,14 @@ namespace Newtonsoft.Json.Linq /// The type to convert the values to. /// The source collection type. /// An that contains the converted values of every token in the source collection. - public static IEnumerable Children(this IEnumerable source) where T : JToken + public static IEnumerable Children(this IEnumerable source) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); return source.SelectMany(c => c.Children()).Convert(); } - internal static IEnumerable Convert(this IEnumerable source) where T : JToken + internal static IEnumerable Convert(this IEnumerable source) where T : JToken { ValidationUtils.ArgumentNotNull(source, nameof(source)); @@ -253,8 +253,7 @@ namespace Newtonsoft.Json.Linq } } - [return: MaybeNull] - internal static U Convert(this T token) where T : JToken? + internal static U? Convert(this T token) where T : JToken? { if (token == null) { diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs index 4b30e44e..6afeca6d 100644 --- a/Src/Newtonsoft.Json/Linq/JContainer.cs +++ b/Src/Newtonsoft.Json/Linq/JContainer.cs @@ -273,7 +273,7 @@ namespace Newtonsoft.Json.Linq /// /// A containing the child values of this , in document order. /// - public override IEnumerable Values() + public override IEnumerable Values() where T : default { return ChildrenTokens.Convert(); } @@ -316,7 +316,7 @@ namespace Newtonsoft.Json.Linq } } - internal bool IsMultiContent([NotNull]object? content) + internal bool IsMultiContent([NotNullWhen(true)]object? content) { return (content is IEnumerable && !(content is string) && !(content is JToken) && !(content is byte[])); } diff --git a/Src/Newtonsoft.Json/Linq/JEnumerable.cs b/Src/Newtonsoft.Json/Linq/JEnumerable.cs index 93bbe1a7..541f1beb 100644 --- a/Src/Newtonsoft.Json/Linq/JEnumerable.cs +++ b/Src/Newtonsoft.Json/Linq/JEnumerable.cs @@ -88,7 +88,7 @@ namespace Newtonsoft.Json.Linq return JEnumerable.Empty; } - return new JEnumerable(_enumerable.Values(key)); + return new JEnumerable(_enumerable.Values(key)!); } } diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs index 4fc10f97..7487b9a4 100644 --- a/Src/Newtonsoft.Json/Linq/JToken.cs +++ b/Src/Newtonsoft.Json/Linq/JToken.cs @@ -334,7 +334,7 @@ namespace Newtonsoft.Json.Linq /// The type to convert the token to. /// The token key. /// The converted token value. - public virtual T Value(object key) + public virtual T? Value(object key) { JToken? token = this[key]; @@ -378,7 +378,7 @@ namespace Newtonsoft.Json.Linq /// /// The type to convert the values to. /// A containing the child values of this , in document order. - public virtual IEnumerable Values() + public virtual IEnumerable Values() { throw new InvalidOperationException("Cannot access child value on {0}.".FormatWith(CultureInfo.InvariantCulture, GetType())); } @@ -1929,8 +1929,7 @@ namespace Newtonsoft.Json.Linq /// /// The object type that the token will be deserialized to. /// The new object created from the JSON value. - [return: MaybeNull] - public T ToObject() + public T? ToObject() { #pragma warning disable CS8601 // Possible null reference assignment. return (T)ToObject(typeof(T)); @@ -2065,8 +2064,7 @@ namespace Newtonsoft.Json.Linq /// The object type that the token will be deserialized to. /// The that will be used when creating the object. /// The new object created from the JSON value. - [return: MaybeNull] - public T ToObject(JsonSerializer jsonSerializer) + public T? ToObject(JsonSerializer jsonSerializer) { #pragma warning disable CS8601 // Possible null reference assignment. return (T)ToObject(typeof(T), jsonSerializer); diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index d5aa1eff..d39ea121 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -841,7 +841,7 @@ namespace Newtonsoft.Json.Linq /// true if the current object is equal to the parameter; otherwise, false. /// /// An object to compare with this object. - public bool Equals([AllowNull] JValue other) + public bool Equals(JValue? other) { if (other == null) { diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj index 95dad1e4..ea973f48 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj @@ -2,7 +2,7 @@ net45;net40;net35;net20;netstandard1.0;netstandard1.3;netstandard2.0 $(LibraryFrameworks) - 8.0 + 9.0 11.0.0.0 11.0.1 diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs index 64c921dc..c54480b4 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs @@ -589,7 +589,7 @@ namespace Newtonsoft.Json.Serialization throw JsonSerializationException.Create(reader, message); } - private bool ReadMetadataPropertiesToken(JTokenReader reader, ref Type? objectType, ref JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue, [NotNullWhen(true)]out object? newValue, out string? id) + private bool ReadMetadataPropertiesToken(JTokenReader reader, ref Type? objectType, ref JsonContract? contract, JsonProperty? member, JsonContainerContract? containerContract, JsonProperty? containerMember, object? existingValue, out object? newValue, out string? id) { id = null; newValue = null; diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs index 2a21a4f7..675b5fed 100644 --- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs +++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs @@ -528,7 +528,7 @@ namespace Newtonsoft.Json.Serialization OnSerialized(writer, contract, value); } - private bool CalculatePropertyValues(JsonWriter writer, object value, JsonContainerContract contract, JsonProperty? member, JsonProperty property, [NotNullWhen(true)]out JsonContract? memberContract, [NotNullWhen(true)]out object? memberValue) + private bool CalculatePropertyValues(JsonWriter writer, object value, JsonContainerContract contract, JsonProperty? member, JsonProperty property, [NotNullWhen(true)]out JsonContract? memberContract, out object? memberValue) { if (!property.Ignored && property.Readable && ShouldSerialize(writer, property, value) && IsSpecified(writer, property, value)) { @@ -542,14 +542,14 @@ namespace Newtonsoft.Json.Serialization if (ShouldWriteProperty(memberValue, contract as JsonObjectContract, property)) { - if (ShouldWriteReference(memberValue, property, memberContract!, contract, member)) + if (ShouldWriteReference(memberValue, property, memberContract, contract, member)) { property.WritePropertyName(writer); WriteReference(writer, memberValue!); return false; } - if (!CheckForCircularReference(writer, memberValue, property, memberContract!, contract, member)) + if (!CheckForCircularReference(writer, memberValue, property, memberContract, contract, member)) { return false; } @@ -568,7 +568,9 @@ namespace Newtonsoft.Json.Serialization } } +#pragma warning disable CS8762 // Parameter must have a non-null value when exiting in some condition. return true; +#pragma warning restore CS8762 // Parameter must have a non-null value when exiting in some condition. } } diff --git a/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs b/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs index 80ff463a..e863e735 100644 --- a/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/AsyncUtils.cs @@ -61,9 +61,9 @@ namespace Newtonsoft.Json.Utilities public static Task FromCanceled(this CancellationToken cancellationToken) { MiscellaneousUtils.Assert(cancellationToken.IsCancellationRequested); -#pragma warning disable CS8653 // A default expression introduces a null value for a type parameter. +#pragma warning disable CS8603 // Possible null reference return. return new Task(() => default, cancellationToken); -#pragma warning restore CS8653 // A default expression introduces a null value for a type parameter. +#pragma warning restore CS8603 // Possible null reference return. } // Task.Delay(0) is optimised as a cached task within the framework, and indeed diff --git a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs index 1d2ed07e..9b62e070 100644 --- a/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs +++ b/Src/Newtonsoft.Json/Utilities/DictionaryWrapper.cs @@ -166,7 +166,9 @@ namespace Newtonsoft.Json.Utilities } } - public bool TryGetValue(TKey key, [MaybeNull]out TValue value) +#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). + public bool TryGetValue(TKey key, out TValue? value) +#pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes). { if (_dictionary != null) { diff --git a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs index fbcacf97..9619e699 100644 --- a/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/JavaScriptUtils.cs @@ -629,7 +629,7 @@ namespace Newtonsoft.Json.Utilities return true; } - private static bool TryGetDateConstructorValue(JsonReader reader, out long? integer, out string? errorMessage) + private static bool TryGetDateConstructorValue(JsonReader reader, out long? integer, [NotNullWhen(false)] out string? errorMessage) { integer = null; errorMessage = null; diff --git a/Src/global.json b/Src/global.json index 2223a05e..2cb2ac9b 100644 --- a/Src/global.json +++ b/Src/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.0.100" + "version": "5.0.100" } } \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a48f9595..e946ce43 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -32,7 +32,7 @@ steps: write-host "Prerelease $nugetPrerelease" -fore white $assemblyVersion = if ($version.Assembly) { $version.Assembly } else { "$($version.Major).0.0.0" } write-host "Assembly $assemblyVersion" -fore white - .\Build\runbuild.ps1 -properties @{"majorVersion"="$($version.Major).0"; "majorWithReleaseVersion"="$($version.Major).0.$($version.Release)"; "nugetPrerelease"=$nugetPrerelease; "assemblyVersion"=$assemblyVersion; "zipFileName"="Json$($version.Major)0r$($version.Release).zip"; "signAssemblies"=$sign; "signKeyPath"=$keyPath; "treatWarningsAsErrors"=$true; "buildNuGet"=$true} + .\Build\runbuild.ps1 -properties @{"majorVersion"="$($version.Major).0"; "majorWithReleaseVersion"="$($version.Major).0.$($version.Release)"; "nugetPrerelease"=$nugetPrerelease; "assemblyVersion"=$assemblyVersion; "zipFileName"="Json$($version.Major)0r$($version.Release).zip"; "signAssemblies"=$sign; "signKeyPath"=$keyPath; "treatWarningsAsErrors"=$true; "buildNuGet"=$true; "ensureNetCliSdk"=$false} env: BuildId: $(Build.BuildId) SourceBranch: $(Build.SourceBranch)