Skip to content

Commit 4f73e74

Browse files
authored
Fix MissingMethodException from JToken.WriteTo (JamesNK#3104)
1 parent e5f6715 commit 4f73e74

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Src/Newtonsoft.Json/JsonValidatingReader.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,11 @@ private void WriteToken(IList<JsonSchemaModel> schemas)
660660
if (!schema.Enum.ContainsValue(finishedItem, JToken.EqualityComparer))
661661
{
662662
StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
663+
#pragma warning disable IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
664+
#pragma warning disable IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
663665
finishedItem.WriteTo(new JsonTextWriter(sw));
666+
#pragma warning restore IL3050 // Calling members annotated with 'RequiresDynamicCodeAttribute' may break functionality when AOT compiling.
667+
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
664668

665669
RaiseError("Value {0} is not defined in enum.".FormatWith(CultureInfo.InvariantCulture, sw.ToString()), schema);
666670
}

Src/Newtonsoft.Json/Linq/JToken.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,15 @@ public void Replace(JToken value)
438438
_parent.ReplaceItem(this, value);
439439
}
440440

441+
// TODO: Make public in Newtonsoft.Json 14.0+
442+
// See https://github.com/JamesNK/Newtonsoft.Json/issues/3084
441443
/// <summary>
442444
/// Writes this token to a <see cref="JsonWriter"/>.
443445
/// </summary>
444446
/// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
445447
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "WriteTo without converters is safe.")]
446448
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "WriteTo without converters is safe.")]
447-
public void WriteTo(JsonWriter writer)
449+
private void WriteTo(JsonWriter writer)
448450
{
449451
WriteTo(writer, CollectionUtils.ArrayEmpty<JsonConverter>());
450452
}

0 commit comments

Comments
 (0)