Skip to content

Conversation

@walterlv
Copy link
Member

@walterlv walterlv commented Nov 7, 2025

即使 JToken 类型的属性已经被 JsonIgnore 了,仍然生成了如下代码。并且 ElementInfo = this.JToken, 那句是无穷递归。

// <auto-generated/>
#nullable enable

// Suppress warnings about [Obsolete] member usage in generated code.
#pragma warning disable CS0618

namespace dotnetCampus.Ipc.Serialization
{
    internal partial class IpcInternalJsonSerializerContext
    {
        private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Newtonsoft.Json.Linq.JToken>? _JToken;
        public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::Newtonsoft.Json.Linq.JToken> JToken
        {
            get
            {
                if (_JToken == null)
                {
                    global::System.Text.Json.Serialization.JsonConverter? customConverter;
                    if (Options.Converters.Count > 0 && (customConverter = GetRuntimeProvidedCustomConverter(typeof(global::Newtonsoft.Json.Linq.JToken))) != null)
                    {
                        _JToken = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateValueInfo<global::Newtonsoft.Json.Linq.JToken>(Options, customConverter);
                    }
                    else
                    {
                        global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::Newtonsoft.Json.Linq.JToken> info = new global::System.Text.Json.Serialization.Metadata.JsonCollectionInfoValues<global::Newtonsoft.Json.Linq.JToken>()
                            {
                                ObjectCreator = null,
                                KeyInfo = null,
                                ElementInfo = this.JToken,
                                NumberHandling = default,
                                SerializeHandler = JTokenSerializeHandler
                            };
            
                            _JToken = global::System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateIEnumerableInfo<global::Newtonsoft.Json.Linq.JToken, global::Newtonsoft.Json.Linq.JToken>(Options, info);
            
                    }
                }
        
                return _JToken;
            }
        }
        
        private static void JTokenSerializeHandler(global::System.Text.Json.Utf8JsonWriter writer, global::Newtonsoft.Json.Linq.JToken? value)
        {
            if (value == null)
            {
                writer.WriteNullValue();
                return;
            }
        
            writer.WriteStartArray();
        
            foreach (global::Newtonsoft.Json.Linq.JToken element in value)
            {
                JTokenSerializeHandler(writer, element!);
            }
        
            writer.WriteEndArray();
        }
    }
}

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an explicit dependency on System.Text.Json version 8.0.6 for the .NET 6.0 target framework to work around bugs and limitations in the .NET 6/7 built-in version.

  • Adds System.Text.Json package reference specifically for net6.0 target framework in the project file
  • Defines the package version (8.0.6) in the central package management file

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/dotnetCampus.Ipc/dotnetCampus.Ipc.csproj Adds conditional package reference to System.Text.Json for net6.0 target framework with explanatory comments
Directory.Packages.props Adds System.Text.Json version 8.0.6 to centralized package version management

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lindexi lindexi enabled auto-merge November 7, 2025 08:19
@lindexi lindexi disabled auto-merge November 7, 2025 08:23
@lindexi lindexi merged commit 042dec6 into main Nov 7, 2025
10 checks passed
@lindexi lindexi deleted the t/walterlv/stack-overflow branch November 7, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants