diff --git a/Src/Newtonsoft.Json/Converters/BinaryConverter.cs b/Src/Newtonsoft.Json/Converters/BinaryConverter.cs
index 47833a2a..57bcdee1 100644
--- a/Src/Newtonsoft.Json/Converters/BinaryConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/BinaryConverter.cs
@@ -29,6 +29,7 @@ using System.Globalization;
using Newtonsoft.Json.Utilities;
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
#if HAVE_ADO_NET
using System.Data.SqlTypes;
#endif
@@ -38,6 +39,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts a binary value to and from a base 64 string value.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class BinaryConverter : JsonConverter
{
#if HAVE_LINQ
diff --git a/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs b/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs
index f693ce57..ae3b2a5e 100644
--- a/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/CustomCreationConverter.cs
@@ -24,6 +24,7 @@
#endregion
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Newtonsoft.Json.Utilities;
@@ -33,6 +34,8 @@ namespace Newtonsoft.Json.Converters
/// Creates a custom object.
///
/// The object type to convert.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public abstract class CustomCreationConverter : JsonConverter
{
///
diff --git a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs
index 214728e6..3b31915a 100644
--- a/Src/Newtonsoft.Json/Converters/DataSetConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/DataSetConverter.cs
@@ -26,13 +26,17 @@
#if HAVE_ADO_NET
using System;
using System.Data;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Serialization;
+using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Converters
{
///
/// Converts a to and from JSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class DataSetConverter : JsonConverter
{
///
diff --git a/Src/Newtonsoft.Json/Converters/DataTableConverter.cs b/Src/Newtonsoft.Json/Converters/DataTableConverter.cs
index 1a32e512..a5c50878 100644
--- a/Src/Newtonsoft.Json/Converters/DataTableConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/DataTableConverter.cs
@@ -26,6 +26,7 @@
#if HAVE_ADO_NET
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Newtonsoft.Json.Utilities;
using System;
@@ -37,6 +38,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts a to and from JSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class DataTableConverter : JsonConverter
{
///
diff --git a/Src/Newtonsoft.Json/Converters/DiscriminatedUnionConverter.cs b/Src/Newtonsoft.Json/Converters/DiscriminatedUnionConverter.cs
index c4c5d08a..93bc559e 100644
--- a/Src/Newtonsoft.Json/Converters/DiscriminatedUnionConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/DiscriminatedUnionConverter.cs
@@ -28,6 +28,7 @@ using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
#if !HAVE_LINQ
using Newtonsoft.Json.Utilities.LinqBridge;
#else
@@ -43,6 +44,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts a F# discriminated union type to and from JSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class DiscriminatedUnionConverter : JsonConverter
{
#region UnionDefinition
diff --git a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs
index 757c8fac..947aeba9 100644
--- a/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/EntityKeyMemberConverter.cs
@@ -26,6 +26,7 @@
#if HAVE_ENTITY_FRAMEWORK
using System;
using Newtonsoft.Json.Serialization;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Newtonsoft.Json.Utilities;
using System.Diagnostics;
@@ -35,6 +36,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts an Entity Framework to and from JSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class EntityKeyMemberConverter : JsonConverter
{
private const string EntityKeyMemberFullTypeName = "System.Data.EntityKeyMember";
@@ -157,7 +160,7 @@ namespace Newtonsoft.Json.Converters
///
public override bool CanConvert(Type objectType)
{
- return objectType.AssignableToTypeName(EntityKeyMemberFullTypeName, false);
+ return objectType.AssignableToTypeName(EntityKeyMemberFullTypeName);
}
}
}
diff --git a/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs b/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs
index 0221e933..14bc9544 100644
--- a/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/KeyValuePairConverter.cs
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities;
using System.Reflection;
@@ -34,6 +35,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts a to and from JSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class KeyValuePairConverter : JsonConverter
{
private const string KeyName = "Key";
diff --git a/Src/Newtonsoft.Json/Converters/RegexConverter.cs b/Src/Newtonsoft.Json/Converters/RegexConverter.cs
index 13db1bb5..5868fc9b 100644
--- a/Src/Newtonsoft.Json/Converters/RegexConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/RegexConverter.cs
@@ -24,6 +24,7 @@
#endregion
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Bson;
using System.Globalization;
@@ -36,6 +37,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts a to and from JSON and BSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class RegexConverter : JsonConverter
{
private const string PatternName = "Pattern";
diff --git a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs
index a9840080..5abb555b 100644
--- a/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/StringEnumConverter.cs
@@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Runtime.Serialization;
@@ -44,6 +45,8 @@ namespace Newtonsoft.Json.Converters
///
/// Converts an to and from its name string value.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class StringEnumConverter : JsonConverter
{
///
diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs
index 12bde515..f4c0c193 100644
--- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs
@@ -2198,13 +2198,13 @@ namespace Newtonsoft.Json.Converters
public override bool CanConvert(Type valueType)
{
#if HAVE_XLINQ
- if (valueType.AssignableToTypeName("System.Xml.Linq.XObject", false))
+ if (valueType.AssignableToTypeName("System.Xml.Linq.XObject"))
{
return IsXObject(valueType);
}
#endif
#if HAVE_XML_DOCUMENT
- if (valueType.AssignableToTypeName("System.Xml.XmlNode", false))
+ if (valueType.AssignableToTypeName("System.Xml.XmlNode"))
{
return IsXmlNode(valueType);
}
diff --git a/Src/Newtonsoft.Json/JsonConvert.cs b/Src/Newtonsoft.Json/JsonConvert.cs
index 1fa3f219..b507d43e 100644
--- a/Src/Newtonsoft.Json/JsonConvert.cs
+++ b/Src/Newtonsoft.Json/JsonConvert.cs
@@ -525,6 +525,8 @@ namespace Newtonsoft.Json
/// The object to serialize.
/// A JSON string representation of the object.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value)
{
return SerializeObject(value, null, (JsonSerializerSettings?)null);
@@ -539,6 +541,8 @@ namespace Newtonsoft.Json
/// A JSON string representation of the object.
///
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, Formatting formatting)
{
return SerializeObject(value, formatting, (JsonSerializerSettings?)null);
@@ -551,6 +555,8 @@ namespace Newtonsoft.Json
/// A collection of converters used while serializing.
/// A JSON string representation of the object.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, params JsonConverter[] converters)
{
JsonSerializerSettings? settings = (converters != null && converters.Length > 0)
@@ -568,6 +574,8 @@ namespace Newtonsoft.Json
/// A collection of converters used while serializing.
/// A JSON string representation of the object.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, Formatting formatting, params JsonConverter[] converters)
{
JsonSerializerSettings? settings = (converters != null && converters.Length > 0)
@@ -587,6 +595,8 @@ namespace Newtonsoft.Json
/// A JSON string representation of the object.
///
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, JsonSerializerSettings? settings)
{
return SerializeObject(value, null, settings);
@@ -607,6 +617,8 @@ namespace Newtonsoft.Json
/// A JSON string representation of the object.
///
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, Type? type, JsonSerializerSettings? settings)
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
@@ -625,6 +637,8 @@ namespace Newtonsoft.Json
/// A JSON string representation of the object.
///
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, Formatting formatting, JsonSerializerSettings? settings)
{
return SerializeObject(value, null, formatting, settings);
@@ -646,6 +660,8 @@ namespace Newtonsoft.Json
/// A JSON string representation of the object.
///
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeObject(object? value, Type? type, Formatting formatting, JsonSerializerSettings? settings)
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
@@ -654,6 +670,8 @@ namespace Newtonsoft.Json
return SerializeObjectInternal(value, type, jsonSerializer);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private static string SerializeObjectInternal(object? value, Type? type, JsonSerializer jsonSerializer)
{
StringBuilder sb = new StringBuilder(256);
@@ -676,6 +694,8 @@ namespace Newtonsoft.Json
/// The JSON to deserialize.
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static object? DeserializeObject(string value)
{
return DeserializeObject(value, null, (JsonSerializerSettings?)null);
@@ -691,6 +711,8 @@ namespace Newtonsoft.Json
///
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static object? DeserializeObject(string value, JsonSerializerSettings settings)
{
return DeserializeObject(value, null, settings);
@@ -703,6 +725,8 @@ namespace Newtonsoft.Json
/// The of object being deserialized.
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static object? DeserializeObject(string value, Type type)
{
return DeserializeObject(value, type, (JsonSerializerSettings?)null);
@@ -715,6 +739,8 @@ namespace Newtonsoft.Json
/// The JSON to deserialize.
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static T? DeserializeObject(string value)
{
return DeserializeObject(value, (JsonSerializerSettings?)null);
@@ -732,6 +758,8 @@ namespace Newtonsoft.Json
/// The anonymous type object.
/// The deserialized anonymous type from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static T? DeserializeAnonymousType(string value, T anonymousTypeObject)
{
return DeserializeObject(value);
@@ -753,6 +781,8 @@ namespace Newtonsoft.Json
///
/// The deserialized anonymous type from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static T? DeserializeAnonymousType(string value, T anonymousTypeObject, JsonSerializerSettings settings)
{
return DeserializeObject(value, settings);
@@ -766,6 +796,8 @@ namespace Newtonsoft.Json
/// Converters to use while deserializing.
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static T? DeserializeObject(string value, params JsonConverter[] converters)
{
return (T?)DeserializeObject(value, typeof(T), converters);
@@ -782,6 +814,8 @@ namespace Newtonsoft.Json
///
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static T? DeserializeObject(string value, JsonSerializerSettings? settings)
{
return (T?)DeserializeObject(value, typeof(T), settings);
@@ -795,6 +829,8 @@ namespace Newtonsoft.Json
/// Converters to use while deserializing.
/// The deserialized object from the JSON string.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static object? DeserializeObject(string value, Type type, params JsonConverter[] converters)
{
JsonSerializerSettings? settings = (converters != null && converters.Length > 0)
@@ -814,6 +850,8 @@ namespace Newtonsoft.Json
/// If this is null, default serialization settings will be used.
///
/// The deserialized object from the JSON string.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static object? DeserializeObject(string value, Type? type, JsonSerializerSettings? settings)
{
ValidationUtils.ArgumentNotNull(value, nameof(value));
@@ -840,6 +878,8 @@ namespace Newtonsoft.Json
/// The JSON to populate values from.
/// The target object to populate values onto.
[DebuggerStepThrough]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static void PopulateObject(string value, object target)
{
PopulateObject(value, target, null);
@@ -854,6 +894,8 @@ namespace Newtonsoft.Json
/// The used to deserialize the object.
/// If this is null, default serialization settings will be used.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static void PopulateObject(string value, object target, JsonSerializerSettings? settings)
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(settings);
@@ -883,6 +925,8 @@ namespace Newtonsoft.Json
///
/// The node to serialize.
/// A JSON string of the .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeXmlNode(XmlNode? node)
{
return SerializeXmlNode(node, Formatting.None);
@@ -894,6 +938,8 @@ namespace Newtonsoft.Json
/// The node to serialize.
/// Indicates how the output should be formatted.
/// A JSON string of the .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeXmlNode(XmlNode? node, Formatting formatting)
{
XmlNodeConverter converter = new XmlNodeConverter();
@@ -908,6 +954,8 @@ namespace Newtonsoft.Json
/// Indicates how the output should be formatted.
/// Omits writing the root object.
/// A JSON string of the .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeXmlNode(XmlNode? node, Formatting formatting, bool omitRootObject)
{
XmlNodeConverter converter = new XmlNodeConverter { OmitRootObject = omitRootObject };
@@ -920,6 +968,8 @@ namespace Newtonsoft.Json
///
/// The JSON string.
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XmlDocument? DeserializeXmlNode(string value)
{
return DeserializeXmlNode(value, null);
@@ -931,6 +981,8 @@ namespace Newtonsoft.Json
/// The JSON string.
/// The name of the root element to append when deserializing.
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XmlDocument? DeserializeXmlNode(string value, string? deserializeRootElementName)
{
return DeserializeXmlNode(value, deserializeRootElementName, false);
@@ -947,6 +999,8 @@ namespace Newtonsoft.Json
/// This attribute helps preserve arrays when converting the written XML back to JSON.
///
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XmlDocument? DeserializeXmlNode(string value, string? deserializeRootElementName, bool writeArrayAttribute)
{
return DeserializeXmlNode(value, deserializeRootElementName, writeArrayAttribute, false);
@@ -969,6 +1023,8 @@ namespace Newtonsoft.Json
/// as part of the XML element name.
///
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XmlDocument? DeserializeXmlNode(string value, string? deserializeRootElementName, bool writeArrayAttribute, bool encodeSpecialCharacters)
{
XmlNodeConverter converter = new XmlNodeConverter();
@@ -986,6 +1042,8 @@ namespace Newtonsoft.Json
///
/// The node to convert to JSON.
/// A JSON string of the .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeXNode(XObject? node)
{
return SerializeXNode(node, Formatting.None);
@@ -997,6 +1055,8 @@ namespace Newtonsoft.Json
/// The node to convert to JSON.
/// Indicates how the output should be formatted.
/// A JSON string of the .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeXNode(XObject? node, Formatting formatting)
{
return SerializeXNode(node, formatting, false);
@@ -1009,6 +1069,8 @@ namespace Newtonsoft.Json
/// Indicates how the output should be formatted.
/// Omits writing the root object.
/// A JSON string of the .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static string SerializeXNode(XObject? node, Formatting formatting, bool omitRootObject)
{
XmlNodeConverter converter = new XmlNodeConverter { OmitRootObject = omitRootObject };
@@ -1021,6 +1083,8 @@ namespace Newtonsoft.Json
///
/// The JSON string.
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XDocument? DeserializeXNode(string value)
{
return DeserializeXNode(value, null);
@@ -1032,6 +1096,8 @@ namespace Newtonsoft.Json
/// The JSON string.
/// The name of the root element to append when deserializing.
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XDocument? DeserializeXNode(string value, string? deserializeRootElementName)
{
return DeserializeXNode(value, deserializeRootElementName, false);
@@ -1048,6 +1114,8 @@ namespace Newtonsoft.Json
/// This attribute helps preserve arrays when converting the written XML back to JSON.
///
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XDocument? DeserializeXNode(string value, string? deserializeRootElementName, bool writeArrayAttribute)
{
return DeserializeXNode(value, deserializeRootElementName, writeArrayAttribute, false);
@@ -1070,6 +1138,8 @@ namespace Newtonsoft.Json
/// as part of the XML element name.
///
/// The deserialized .
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static XDocument? DeserializeXNode(string value, string? deserializeRootElementName, bool writeArrayAttribute, bool encodeSpecialCharacters)
{
XmlNodeConverter converter = new XmlNodeConverter();
diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs
index 13e3a9c6..b72625df 100644
--- a/Src/Newtonsoft.Json/JsonSerializer.cs
+++ b/Src/Newtonsoft.Json/JsonSerializer.cs
@@ -44,6 +44,8 @@ namespace Newtonsoft.Json
/// Serializes and deserializes objects into and from the JSON format.
/// The enables you to control how objects are encoded into JSON.
///
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public class JsonSerializer
{
internal TypeNameHandling _typeNameHandling;
diff --git a/Src/Newtonsoft.Json/Linq/JArray.Async.cs b/Src/Newtonsoft.Json/Linq/JArray.Async.cs
index 25ffe4ef..f80556a3 100644
--- a/Src/Newtonsoft.Json/Linq/JArray.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JArray.Async.cs
@@ -25,6 +25,7 @@
#if HAVE_ASYNC
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -41,6 +42,8 @@ namespace Newtonsoft.Json.Linq
/// The token to monitor for cancellation requests.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override async Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
await writer.WriteStartArrayAsync(cancellationToken).ConfigureAwait(false);
diff --git a/Src/Newtonsoft.Json/Linq/JArray.cs b/Src/Newtonsoft.Json/Linq/JArray.cs
index c589e211..2abe6d1a 100644
--- a/Src/Newtonsoft.Json/Linq/JArray.cs
+++ b/Src/Newtonsoft.Json/Linq/JArray.cs
@@ -26,6 +26,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Utilities;
using System.IO;
using System.Globalization;
@@ -188,6 +189,8 @@ namespace Newtonsoft.Json.Linq
///
/// The object that will be used to create .
/// A with the values of the specified object.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public new static JArray FromObject(object o)
{
return FromObject(o, JsonSerializer.CreateDefault());
@@ -199,6 +202,8 @@ namespace Newtonsoft.Json.Linq
/// The object that will be used to create .
/// The that will be used to read the object.
/// A with the values of the specified object.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public new static JArray FromObject(object o, JsonSerializer jsonSerializer)
{
JToken token = FromObjectInternal(o, jsonSerializer);
@@ -216,6 +221,8 @@ namespace Newtonsoft.Json.Linq
///
/// A into which this method will write.
/// A collection of which will be used when writing the token.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartArray();
diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs b/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs
index bdbeff69..5b69dfc7 100644
--- a/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JConstructor.Async.cs
@@ -25,6 +25,7 @@
#if HAVE_ASYNC
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -41,6 +42,8 @@ namespace Newtonsoft.Json.Linq
/// The token to monitor for cancellation requests.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override async Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
await writer.WriteStartConstructorAsync(_name ?? string.Empty, cancellationToken).ConfigureAwait(false);
diff --git a/Src/Newtonsoft.Json/Linq/JConstructor.cs b/Src/Newtonsoft.Json/Linq/JConstructor.cs
index 703dbbc1..d29c2b89 100644
--- a/Src/Newtonsoft.Json/Linq/JConstructor.cs
+++ b/Src/Newtonsoft.Json/Linq/JConstructor.cs
@@ -26,6 +26,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Utilities;
using System.Globalization;
@@ -163,6 +164,8 @@ namespace Newtonsoft.Json.Linq
///
/// A into which this method will write.
/// A collection of which will be used when writing the token.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartConstructor(_name!);
diff --git a/Src/Newtonsoft.Json/Linq/JContainer.cs b/Src/Newtonsoft.Json/Linq/JContainer.cs
index e19be361..dd9ef762 100644
--- a/Src/Newtonsoft.Json/Linq/JContainer.cs
+++ b/Src/Newtonsoft.Json/Linq/JContainer.cs
@@ -959,9 +959,17 @@ namespace Newtonsoft.Json.Linq
PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
+#if HAVE_APPCONTEXT
+ if (!ComponentModelIsSupported)
+ {
+ throw new NotSupportedException(ComponentModelNotSupportedMessage);
+ }
+#endif
ICustomTypeDescriptor? d = First as ICustomTypeDescriptor;
+#pragma warning disable IL2026
return d?.GetProperties() ?? new PropertyDescriptorCollection(CollectionUtils.ArrayEmpty());
+#pragma warning restore IL2026
}
#endif
diff --git a/Src/Newtonsoft.Json/Linq/JObject.Async.cs b/Src/Newtonsoft.Json/Linq/JObject.Async.cs
index 67f01fe5..c317b31e 100644
--- a/Src/Newtonsoft.Json/Linq/JObject.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JObject.Async.cs
@@ -26,6 +26,7 @@
#if HAVE_ASYNC
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -42,6 +43,8 @@ namespace Newtonsoft.Json.Linq
/// The token to monitor for cancellation requests.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
Task t = writer.WriteStartObjectAsync(cancellationToken);
@@ -62,6 +65,7 @@ namespace Newtonsoft.Json.Linq
return writer.WriteEndObjectAsync(cancellationToken);
// Local functions, params renamed (capitalized) so as not to capture and allocate when calling async
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
async Task AwaitProperties(Task task, int i, JsonWriter Writer, CancellationToken CancellationToken, JsonConverter[] Converters)
{
await task.ConfigureAwait(false);
diff --git a/Src/Newtonsoft.Json/Linq/JObject.cs b/Src/Newtonsoft.Json/Linq/JObject.cs
index fab460da..41d64347 100644
--- a/Src/Newtonsoft.Json/Linq/JObject.cs
+++ b/Src/Newtonsoft.Json/Linq/JObject.cs
@@ -485,6 +485,8 @@ namespace Newtonsoft.Json.Linq
///
/// The object that will be used to create .
/// A with the values of the specified object.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public new static JObject FromObject(object o)
{
return FromObject(o, JsonSerializer.CreateDefault());
@@ -496,6 +498,8 @@ namespace Newtonsoft.Json.Linq
/// The object that will be used to create .
/// The that will be used to read the object.
/// A with the values of the specified object.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public new static JObject FromObject(object o, JsonSerializer jsonSerializer)
{
JToken token = FromObjectInternal(o, jsonSerializer);
@@ -513,6 +517,8 @@ namespace Newtonsoft.Json.Linq
///
/// A into which this method will write.
/// A collection of which will be used when writing the token.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartObject();
@@ -742,11 +748,13 @@ namespace Newtonsoft.Json.Linq
// include custom type descriptor on JObject rather than use a provider because the properties are specific to a type
#region ICustomTypeDescriptor
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
return ((ICustomTypeDescriptor)this).GetProperties(null);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[]? attributes)
{
PropertyDescriptor[] propertiesArray = new PropertyDescriptor[Count];
@@ -775,26 +783,31 @@ namespace Newtonsoft.Json.Linq
return null;
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return new TypeConverter();
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
EventDescriptor? ICustomTypeDescriptor.GetDefaultEvent()
{
return null;
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
PropertyDescriptor? ICustomTypeDescriptor.GetDefaultProperty()
{
return null;
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
object? ICustomTypeDescriptor.GetEditor(Type editorBaseType)
{
return null;
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[]? attributes)
{
return EventDescriptorCollection.Empty;
@@ -828,7 +841,15 @@ namespace Newtonsoft.Json.Linq
///
protected override DynamicMetaObject GetMetaObject(Expression parameter)
{
+#if HAVE_APPCONTEXT
+ if (!DynamicIsSupported)
+ {
+ throw new NotSupportedException(DynamicNotSupportedMessage);
+ }
+#endif
+#pragma warning disable IL2026, IL3050
return new DynamicProxyMetaObject(parameter, this, new JObjectDynamicProxy());
+#pragma warning restore IL2026, IL3050
}
private class JObjectDynamicProxy : DynamicProxy
diff --git a/Src/Newtonsoft.Json/Linq/JProperty.Async.cs b/Src/Newtonsoft.Json/Linq/JProperty.Async.cs
index d1e845dc..d632f51b 100644
--- a/Src/Newtonsoft.Json/Linq/JProperty.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JProperty.Async.cs
@@ -25,6 +25,7 @@
#if HAVE_ASYNC
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -41,6 +42,8 @@ namespace Newtonsoft.Json.Linq
/// The token to monitor for cancellation requests.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
Task task = writer.WritePropertyNameAsync(_name, cancellationToken);
@@ -52,6 +55,8 @@ namespace Newtonsoft.Json.Linq
return WriteToAsync(task, writer, cancellationToken, converters);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private async Task WriteToAsync(Task task, JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
await task.ConfigureAwait(false);
@@ -59,6 +64,8 @@ namespace Newtonsoft.Json.Linq
await WriteValueAsync(writer, cancellationToken, converters).ConfigureAwait(false);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private Task WriteValueAsync(JsonWriter writer, CancellationToken cancellationToken, JsonConverter[] converters)
{
JToken value = Value;
diff --git a/Src/Newtonsoft.Json/Linq/JProperty.cs b/Src/Newtonsoft.Json/Linq/JProperty.cs
index b8c7ace6..5645d239 100644
--- a/Src/Newtonsoft.Json/Linq/JProperty.cs
+++ b/Src/Newtonsoft.Json/Linq/JProperty.cs
@@ -26,6 +26,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Utilities;
using System.Diagnostics;
using System.Globalization;
@@ -342,6 +343,8 @@ namespace Newtonsoft.Json.Linq
///
/// A into which this method will write.
/// A collection of which will be used when writing the token.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WritePropertyName(_name);
diff --git a/Src/Newtonsoft.Json/Linq/JToken.Async.cs b/Src/Newtonsoft.Json/Linq/JToken.Async.cs
index 4d147c2d..9ace19ac 100644
--- a/Src/Newtonsoft.Json/Linq/JToken.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JToken.Async.cs
@@ -26,6 +26,7 @@
#if HAVE_ASYNC
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -42,6 +43,8 @@ namespace Newtonsoft.Json.Linq
/// The token to monitor for cancellation requests.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public virtual Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
throw new NotImplementedException();
@@ -53,11 +56,38 @@ namespace Newtonsoft.Json.Linq
/// A into which this method will write.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public Task WriteToAsync(JsonWriter writer, params JsonConverter[] converters)
{
return WriteToAsync(writer, default, converters);
}
+ ///
+ /// Writes this token to a asynchronously.
+ ///
+ /// A into which this method will write.
+ /// The token to monitor for cancellation requests.
+ /// A that represents the asynchronous write operation.
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "WriteToAsync without converters is safe.")]
+ [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "WriteToAsync without converters is safe.")]
+ public Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken)
+ {
+ return WriteToAsync(writer, default, CollectionUtils.ArrayEmpty());
+ }
+
+ ///
+ /// Writes this token to a asynchronously.
+ ///
+ /// A into which this method will write.
+ /// A that represents the asynchronous write operation.
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "WriteToAsync without converters is safe.")]
+ [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "WriteToAsync without converters is safe.")]
+ public Task WriteToAsync(JsonWriter writer)
+ {
+ return WriteToAsync(writer, default, CollectionUtils.ArrayEmpty());
+ }
+
///
/// Asynchronously creates a from a .
///
diff --git a/Src/Newtonsoft.Json/Linq/JToken.cs b/Src/Newtonsoft.Json/Linq/JToken.cs
index 27f84d8b..c01e51e4 100644
--- a/Src/Newtonsoft.Json/Linq/JToken.cs
+++ b/Src/Newtonsoft.Json/Linq/JToken.cs
@@ -80,6 +80,33 @@ namespace Newtonsoft.Json.Linq
private static readonly JTokenType[] DateTimeTypes = new[] { JTokenType.Date, JTokenType.String, JTokenType.Comment, JTokenType.Raw };
private static readonly JTokenType[] BytesTypes = new[] { JTokenType.Bytes, JTokenType.String, JTokenType.Comment, JTokenType.Raw, JTokenType.Integer };
+#if HAVE_APPCONTEXT
+ [FeatureSwitchDefinition("Newtonsoft.Json.Linq.JToken.SerializationIsSupported")]
+ [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))]
+ [FeatureGuard(typeof(RequiresDynamicCodeAttribute))]
+ internal static bool SerializationIsSupported => AppContext.TryGetSwitch("Newtonsoft.Json.Linq.JToken.SerializationIsSupported", out bool isSupported) ? isSupported : true;
+
+ internal const string SerializationNotSupportedMessage = "Newtonsoft.Json serialization is not compatible with trimming and has been disabled. Newtonsoft.Json.Linq.JToken.SerializationIsSupported is set to false.";
+
+#if HAVE_COMPONENT_MODEL
+ [FeatureSwitchDefinition("Newtonsoft.Json.Linq.JToken.ComponentModelIsSupported")]
+ [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))]
+ internal static bool ComponentModelIsSupported => AppContext.TryGetSwitch("Newtonsoft.Json.Linq.JToken.ComponentModelIsSupported", out bool isSupported) ? isSupported : true;
+
+ internal const string ComponentModelNotSupportedMessage = "Newtonsoft.Json support for System.ComponentModel is not compatible with trimming and has been disabled. Newtonsoft.Json.Linq.JToken.ComponentModelIsSupported is set to false.";
+#endif // HAVE_COMPONENT_MODEL
+
+#if HAVE_DYNAMIC
+ [FeatureSwitchDefinition("Newtonsoft.Json.Linq.JToken.DynamicIsSupported")]
+ [FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))]
+ [FeatureGuard(typeof(RequiresDynamicCodeAttribute))]
+ internal static bool DynamicIsSupported => AppContext.TryGetSwitch("Newtonsoft.Json.Linq.JToken.DynamicIsSupported", out bool isSupported) ? isSupported : true;
+
+ internal const string DynamicNotSupportedMessage = "Newtonsoft.Json support for dynamic is not compatible with trimming and has been disabled. Newtonsoft.Json.Linq.JToken.DynamicIsSupported is set to false.";
+#endif // HAVE_DYNAMIC
+
+#endif // HAVE_APPCONTEXT
+
///
/// Gets a comparer that can compare two tokens for value equality.
///
@@ -411,11 +438,24 @@ namespace Newtonsoft.Json.Linq
_parent.ReplaceItem(this, value);
}
+ ///
+ /// Writes this token to a .
+ ///
+ /// A into which this method will write.
+ [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "WriteTo without converters is safe.")]
+ [UnconditionalSuppressMessage("AOT", "IL3050", Justification = "WriteTo without converters is safe.")]
+ public void WriteTo(JsonWriter writer)
+ {
+ WriteTo(writer, CollectionUtils.ArrayEmpty());
+ }
+
///
/// Writes this token to a .
///
/// A into which this method will write.
/// A collection of which will be used when writing the token.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public abstract void WriteTo(JsonWriter writer, params JsonConverter[] converters);
///
@@ -433,12 +473,32 @@ namespace Newtonsoft.Json.Linq
return ToString(Formatting.Indented);
}
+ ///
+ /// Returns the JSON for this token using the given formatting and converters.
+ ///
+ /// Indicates how the output should be formatted.
+ /// The JSON for this token using the given formatting and converters.
+ public string ToString(Formatting formatting)
+ {
+ using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
+ {
+ JsonTextWriter jw = new JsonTextWriter(sw);
+ jw.Formatting = formatting;
+
+ WriteTo(jw);
+
+ return sw.ToString();
+ }
+ }
+
///
/// Returns the JSON for this token using the given formatting and converters.
///
/// Indicates how the output should be formatted.
/// A collection of s which will be used when writing the token.
/// The JSON for this token using the given formatting and converters.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public string ToString(Formatting formatting, params JsonConverter[] converters)
{
using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
@@ -1889,6 +1949,8 @@ namespace Newtonsoft.Json.Linq
return new JTokenReader(this);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
internal static JToken FromObjectInternal(object o, JsonSerializer jsonSerializer)
{
ValidationUtils.ArgumentNotNull(o, nameof(o));
@@ -1909,6 +1971,8 @@ namespace Newtonsoft.Json.Linq
///
/// The object that will be used to create .
/// A with the value of the specified object.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static JToken FromObject(object o)
{
return FromObjectInternal(o, JsonSerializer.CreateDefault());
@@ -1920,6 +1984,8 @@ namespace Newtonsoft.Json.Linq
/// The object that will be used to create .
/// The that will be used when reading the object.
/// A with the value of the specified object.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static JToken FromObject(object o, JsonSerializer jsonSerializer)
{
return FromObjectInternal(o, jsonSerializer);
@@ -1930,6 +1996,8 @@ namespace Newtonsoft.Json.Linq
///
/// The object type that the token will be deserialized to.
/// The new object created from the JSON value.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public T? ToObject()
{
return (T?)ToObject(typeof(T));
@@ -1940,6 +2008,8 @@ namespace Newtonsoft.Json.Linq
///
/// The object type that the token will be deserialized to.
/// The new object created from the JSON value.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public object? ToObject(Type objectType)
{
if (JsonConvert.DefaultSettings == null)
@@ -2063,6 +2133,8 @@ 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.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public T? ToObject(JsonSerializer jsonSerializer)
{
return (T?)ToObject(typeof(T), jsonSerializer);
@@ -2074,6 +2146,8 @@ 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.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public object? ToObject(Type? objectType, JsonSerializer jsonSerializer)
{
ValidationUtils.ArgumentNotNull(jsonSerializer, nameof(jsonSerializer));
@@ -2414,7 +2488,15 @@ namespace Newtonsoft.Json.Linq
///
protected virtual DynamicMetaObject GetMetaObject(Expression parameter)
{
+#if HAVE_APPCONTEXT
+ if (!DynamicIsSupported)
+ {
+ throw new NotSupportedException(DynamicNotSupportedMessage);
+ }
+#endif
+#pragma warning disable IL2026, IL3050
return new DynamicProxyMetaObject(parameter, this, new DynamicProxy());
+#pragma warning restore IL2026, IL3050
}
///
diff --git a/Src/Newtonsoft.Json/Linq/JValue.Async.cs b/Src/Newtonsoft.Json/Linq/JValue.Async.cs
index e80b880a..e8808a4a 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.Async.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.Async.cs
@@ -26,6 +26,7 @@
#if HAVE_ASYNC
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
#if HAVE_BIG_INTEGER
using System.Numerics;
@@ -45,6 +46,8 @@ namespace Newtonsoft.Json.Linq
/// The token to monitor for cancellation requests.
/// A collection of which will be used when writing the token.
/// A that represents the asynchronous write operation.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override Task WriteToAsync(JsonWriter writer, CancellationToken cancellationToken, params JsonConverter[] converters)
{
if (converters != null && converters.Length > 0 && _value != null)
diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs
index c2f03991..7568960d 100644
--- a/Src/Newtonsoft.Json/Linq/JValue.cs
+++ b/Src/Newtonsoft.Json/Linq/JValue.cs
@@ -727,6 +727,8 @@ namespace Newtonsoft.Json.Linq
///
/// A into which this method will write.
/// A collection of s which will be used when writing the token.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
if (converters != null && converters.Length > 0 && _value != null)
@@ -972,9 +974,19 @@ namespace Newtonsoft.Json.Linq
///
protected override DynamicMetaObject GetMetaObject(Expression parameter)
{
+#if HAVE_APPCONTEXT
+ if (!DynamicIsSupported)
+ {
+ throw new NotSupportedException(DynamicNotSupportedMessage);
+ }
+#endif
+#pragma warning disable IL2026, IL3050
return new DynamicProxyMetaObject(parameter, this, new JValueDynamicProxy());
+#pragma warning restore IL2026, IL3050
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private class JValueDynamicProxy : DynamicProxy
{
public override bool TryConvert(JValue instance, ConvertBinder binder, [NotNullWhen(true)]out object? result)
@@ -1188,7 +1200,15 @@ namespace Newtonsoft.Json.Linq
object IConvertible.ToType(Type conversionType, IFormatProvider? provider)
{
+#if HAVE_APPCONTEXT
+ if (!SerializationIsSupported)
+ {
+ throw new NotSupportedException(SerializationNotSupportedMessage);
+ }
+#endif
+#pragma warning disable IL2026, IL3050
return ToObject(conversionType)!;
+#pragma warning restore IL2026, IL3050
}
#endif
}
diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj
index 47c63018..fe606797 100644
--- a/Src/Newtonsoft.Json/Newtonsoft.Json.csproj
+++ b/Src/Newtonsoft.Json/Newtonsoft.Json.csproj
@@ -1,6 +1,6 @@
- net6.0;net45;net40;net35;net20;netstandard1.0;netstandard1.3;netstandard2.0
+ net8.0;net6.0;net45;net40;net35;net20;netstandard1.0;netstandard1.3;netstandard2.0$(LibraryFrameworks)9.0
@@ -40,6 +40,12 @@
Disable that warning since local builds do not strong-name sign the assembly, causing a mistmatch when comparing
the previously shipped assemblies and current.-->
$(NoWarn);CP0003
+
+
+ true
+ true
+ true
@@ -51,9 +57,13 @@
+
+ Json.NET .NET 8.0
+ HAVE_APPCONTEXT;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_ASYNC_DISPOSABLE;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_EMIT;HAVE_REGEX_TIMEOUTS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_INDEXOF_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_GETHASHCODE_STRING_COMPARISON;HAVE_NULLABLE_ATTRIBUTES;HAVE_DYNAMIC_CODE_COMPILED;HAS_ARRAY_EMPTY;HAVE_DATE_ONLY;$(AdditionalConstants)
+ Json.NET .NET 6.0
- HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_ASYNC_DISPOSABLE;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_EMIT;HAVE_REGEX_TIMEOUTS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_INDEXOF_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_GETHASHCODE_STRING_COMPARISON;HAVE_NULLABLE_ATTRIBUTES;HAVE_DYNAMIC_CODE_COMPILED;HAS_ARRAY_EMPTY;HAVE_DATE_ONLY;$(AdditionalConstants)
+ HAVE_APPCONTEXT;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_ASYNC_DISPOSABLE;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_EMIT;HAVE_REGEX_TIMEOUTS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_INDEXOF_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_REPLACE_STRING_COMPARISON;HAVE_GETHASHCODE_STRING_COMPARISON;HAVE_NULLABLE_ATTRIBUTES;HAVE_DYNAMIC_CODE_COMPILED;HAS_ARRAY_EMPTY;HAVE_DATE_ONLY;$(AdditionalConstants)Json.NET .NET 4.5
@@ -86,10 +96,10 @@
Json.NET .NET Standard 1.3
- NETSTANDARD1_3;PORTABLE;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_SERIALIZATION;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DYNAMIC;HAVE_EXPRESSIONS;HAVE_FSHARP_TYPES;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_BINDER;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_OBSOLETE_FORMATTER_ASSEMBLY_STYLE;HAVE_XML_DOCUMENT;HAVE_CONCURRENT_DICTIONARY;HAVE_ICONVERTIBLE;HAVE_REGEX_TIMEOUTS;HAVE_REGEX_TIMEOUTS;$(AdditionalConstants)
+ HAVE_APPCONTEXT;NETSTANDARD1_3;PORTABLE;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_SERIALIZATION;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DYNAMIC;HAVE_EXPRESSIONS;HAVE_FSHARP_TYPES;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_REFLECTION_BINDER;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_OBSOLETE_FORMATTER_ASSEMBLY_STYLE;HAVE_XML_DOCUMENT;HAVE_CONCURRENT_DICTIONARY;HAVE_ICONVERTIBLE;HAVE_REGEX_TIMEOUTS;HAVE_REGEX_TIMEOUTS;$(AdditionalConstants)Json.NET .NET Standard 2.0
- NETSTANDARD2_0;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_REGEX_TIMEOUTS;$(AdditionalConstants)
+ HAVE_APPCONTEXT;NETSTANDARD2_0;HAVE_ADO_NET;HAVE_APP_DOMAIN;HAVE_ASYNC;HAVE_BIG_INTEGER;HAVE_BINARY_FORMATTER;HAVE_BINARY_SERIALIZATION;HAVE_BINARY_EXCEPTION_SERIALIZATION;HAVE_CHAR_TO_LOWER_WITH_CULTURE;HAVE_CHAR_TO_STRING_WITH_CULTURE;HAVE_COM_ATTRIBUTES;HAVE_COMPONENT_MODEL;HAVE_CONCURRENT_COLLECTIONS;HAVE_COVARIANT_GENERICS;HAVE_DATA_CONTRACTS;HAVE_DATE_TIME_OFFSET;HAVE_DB_NULL_TYPE_CODE;HAVE_DYNAMIC;HAVE_EMPTY_TYPES;HAVE_ENTITY_FRAMEWORK;HAVE_EXPRESSIONS;HAVE_FAST_REVERSE;HAVE_FSHARP_TYPES;HAVE_FULL_REFLECTION;HAVE_GUID_TRY_PARSE;HAVE_HASH_SET;HAVE_ICLONEABLE;HAVE_ICONVERTIBLE;HAVE_IGNORE_DATA_MEMBER_ATTRIBUTE;HAVE_INOTIFY_COLLECTION_CHANGED;HAVE_INOTIFY_PROPERTY_CHANGING;HAVE_ISET;HAVE_LINQ;HAVE_MEMORY_BARRIER;HAVE_METHOD_IMPL_ATTRIBUTE;HAVE_NON_SERIALIZED_ATTRIBUTE;HAVE_READ_ONLY_COLLECTIONS;HAVE_SECURITY_SAFE_CRITICAL_ATTRIBUTE;HAVE_SERIALIZATION_BINDER_BIND_TO_NAME;HAVE_STREAM_READER_WRITER_CLOSE;HAVE_STRING_JOIN_WITH_ENUMERABLE;HAVE_TIME_SPAN_PARSE_WITH_CULTURE;HAVE_TIME_SPAN_TO_STRING_WITH_CULTURE;HAVE_TIME_ZONE_INFO;HAVE_TRACE_WRITER;HAVE_TYPE_DESCRIPTOR;HAVE_UNICODE_SURROGATE_DETECTION;HAVE_VARIANT_TYPE_PARAMETERS;HAVE_VERSION_TRY_PARSE;HAVE_XLINQ;HAVE_XML_DOCUMENT;HAVE_XML_DOCUMENT_TYPE;HAVE_CONCURRENT_DICTIONARY;HAVE_REGEX_TIMEOUTS;$(AdditionalConstants)
\ No newline at end of file
diff --git a/Src/Newtonsoft.Json/Schema/Extensions.cs b/Src/Newtonsoft.Json/Schema/Extensions.cs
index df8ffbaa..4e1e58ea 100644
--- a/Src/Newtonsoft.Json/Schema/Extensions.cs
+++ b/Src/Newtonsoft.Json/Schema/Extensions.cs
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
@@ -57,6 +58,8 @@ namespace Newtonsoft.Json.Schema
/// true if the specified is valid; otherwise, false.
///
[Obsolete("JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschema for more details.")]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static bool IsValid(this JToken source, JsonSchema schema)
{
bool valid = true;
@@ -79,6 +82,8 @@ namespace Newtonsoft.Json.Schema
/// true if the specified is valid; otherwise, false.
///
[Obsolete("JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschema for more details.")]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static bool IsValid(this JToken source, JsonSchema schema, out IList errorMessages)
{
IList errors = new List();
@@ -100,6 +105,8 @@ namespace Newtonsoft.Json.Schema
/// The source to test.
/// The schema to test with.
[Obsolete("JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschema for more details.")]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static void Validate(this JToken source, JsonSchema schema)
{
source.Validate(schema, null);
@@ -117,6 +124,8 @@ namespace Newtonsoft.Json.Schema
/// The schema to test with.
/// The validation event handler.
[Obsolete("JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschema for more details.")]
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public static void Validate(this JToken source, JsonSchema schema, ValidationEventHandler validationEventHandler)
{
ValidationUtils.ArgumentNotNull(source, nameof(source));
diff --git a/Src/Newtonsoft.Json/Schema/JsonSchema.cs b/Src/Newtonsoft.Json/Schema/JsonSchema.cs
index 034bd063..7da54650 100644
--- a/Src/Newtonsoft.Json/Schema/JsonSchema.cs
+++ b/Src/Newtonsoft.Json/Schema/JsonSchema.cs
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
@@ -318,6 +319,8 @@ namespace Newtonsoft.Json.Schema
/// Writes this schema to a .
///
/// A into which this method will write.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public void WriteTo(JsonWriter writer)
{
WriteTo(writer, new JsonSchemaResolver());
@@ -328,6 +331,8 @@ namespace Newtonsoft.Json.Schema
///
/// A into which this method will write.
/// The resolver used.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public void WriteTo(JsonWriter writer, JsonSchemaResolver resolver)
{
ValidationUtils.ArgumentNotNull(writer, nameof(writer));
@@ -345,11 +350,19 @@ namespace Newtonsoft.Json.Schema
///
public override string ToString()
{
+#if HAVE_APPCONTEXT
+ if (!JToken.SerializationIsSupported)
+ {
+ throw new NotSupportedException(JToken.SerializationNotSupportedMessage);
+ }
+#endif
StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
JsonTextWriter jsonWriter = new JsonTextWriter(writer);
jsonWriter.Formatting = Formatting.Indented;
+#pragma warning disable IL2026, IL3050
WriteTo(jsonWriter);
+#pragma warning restore IL2026, IL3050
return writer.ToString();
}
diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs
index 7cdab611..8e604163 100644
--- a/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs
+++ b/Src/Newtonsoft.Json/Schema/JsonSchemaGenerator.cs
@@ -30,6 +30,8 @@ using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Serialization;
+using System.Diagnostics.CodeAnalysis;
+
#if !HAVE_LINQ
using Newtonsoft.Json.Utilities.LinqBridge;
#else
@@ -65,6 +67,8 @@ namespace Newtonsoft.Json.Schema
/// The contract resolver.
public IContractResolver ContractResolver
{
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
get
{
if (_contractResolver == null)
@@ -127,6 +131,8 @@ namespace Newtonsoft.Json.Schema
///
/// The type to generate a from.
/// A generated from the specified type.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public JsonSchema Generate(Type type)
{
return Generate(type, new JsonSchemaResolver(), false);
@@ -138,6 +144,8 @@ namespace Newtonsoft.Json.Schema
/// The type to generate a from.
/// The used to resolve schema references.
/// A generated from the specified type.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public JsonSchema Generate(Type type, JsonSchemaResolver resolver)
{
return Generate(type, resolver, false);
@@ -149,6 +157,8 @@ namespace Newtonsoft.Json.Schema
/// The type to generate a from.
/// Specify whether the generated root will be nullable.
/// A generated from the specified type.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public JsonSchema Generate(Type type, bool rootSchemaNullable)
{
return Generate(type, new JsonSchemaResolver(), rootSchemaNullable);
@@ -161,6 +171,8 @@ namespace Newtonsoft.Json.Schema
/// The used to resolve schema references.
/// Specify whether the generated root will be nullable.
/// A generated from the specified type.
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public JsonSchema Generate(Type type, JsonSchemaResolver resolver, bool rootSchemaNullable)
{
ValidationUtils.ArgumentNotNull(type, nameof(type));
@@ -171,6 +183,8 @@ namespace Newtonsoft.Json.Schema
return GenerateInternal(type, (!rootSchemaNullable) ? Required.Always : Required.Default, false);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private string GetTitle(Type type)
{
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute(type);
@@ -183,6 +197,8 @@ namespace Newtonsoft.Json.Schema
return null;
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private string GetDescription(Type type)
{
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute(type);
@@ -200,6 +216,8 @@ namespace Newtonsoft.Json.Schema
#endif
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private string GetTypeId(Type type, bool explicitOnly)
{
JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute(type);
@@ -225,7 +243,13 @@ namespace Newtonsoft.Json.Schema
}
}
- private JsonSchema GenerateInternal(Type type, Required valueRequired, bool required)
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
+ private JsonSchema GenerateInternal(
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Interfaces)]
+ Type type,
+ Required valueRequired,
+ bool required)
{
ValidationUtils.ArgumentNotNull(type, nameof(type));
@@ -382,6 +406,8 @@ namespace Newtonsoft.Json.Schema
return ((value & flag) == flag);
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private void GenerateObjectSchema(Type type, JsonObjectContract contract)
{
CurrentSchema.Properties = new Dictionary();
diff --git a/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs b/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs
index c5843bed..c15e87e1 100644
--- a/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs
+++ b/Src/Newtonsoft.Json/Schema/JsonSchemaWriter.cs
@@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Utilities;
@@ -52,6 +53,8 @@ namespace Newtonsoft.Json.Schema
_resolver = resolver;
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private void ReferenceOrWriteSchema(JsonSchema schema)
{
if (schema.Id != null && _resolver.GetSchema(schema.Id) != null)
@@ -67,6 +70,8 @@ namespace Newtonsoft.Json.Schema
}
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
public void WriteSchema(JsonSchema schema)
{
ValidationUtils.ArgumentNotNull(schema, nameof(schema));
@@ -167,6 +172,8 @@ namespace Newtonsoft.Json.Schema
_writer.WriteEndObject();
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private void WriteSchemaDictionaryIfNotNull(JsonWriter writer, string propertyName, IDictionary properties)
{
if (properties != null)
@@ -182,6 +189,8 @@ namespace Newtonsoft.Json.Schema
}
}
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
private void WriteItems(JsonSchema schema)
{
if (schema.Items == null && !schema.PositionalItemsValidation)
diff --git a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs
index 40697594..4d68a73f 100644
--- a/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs
+++ b/Src/Newtonsoft.Json/Serialization/CachedAttributeGetter.cs
@@ -24,11 +24,14 @@
#endregion
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Newtonsoft.Json.Utilities;
namespace Newtonsoft.Json.Serialization
{
+ [RequiresUnreferencedCode(MiscellaneousUtils.TrimWarning)]
+ [RequiresDynamicCode(MiscellaneousUtils.AotWarning)]
internal static class CachedAttributeGetter where T : Attribute
{
private static readonly ThreadSafeStore