Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular references in the values contained in the list cannot be ignored. #607

Closed
k-maru opened this issue Aug 19, 2022 · 3 comments
Closed
Labels
Milestone

Comments

@k-maru
Copy link

k-maru commented Aug 19, 2022

version 17.10.2

A stack overflow occurs when a value in the list is a circular reference. "ReferenceLoopHandling.Ignore" does not work. However, the same data can be serialized directly using JsonConvert.SerializeObject.

I verified this with the following code

public class A
{
   public List<B> Bs { get; set; } = new List<B>();
}

public class B
{
       public A A { get; set; }
}

[UsesVerify]
public class UnitTest1
{
    private A ListReferenceData()
    {
        var act = new A()
        {
            Bs = new List<B>()
        };
        act.Bs.Add(new B()
        {
            A = act
        });
        act.Bs.Add(new B()
        {
            A = act
        });
        return act;
    }
    
    [Fact] // Stack overflow
    public async Task List_IgnoreLoopReference()
    {
        var settings = new VerifySettings();
        settings.AddExtraSettings(jsonSetting =>
        {
            jsonSetting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
        });
        await Verify(ListReferenceData(), settings);
    }

    [Fact] // OK
    public async Task List_SerializeNewtonJson()
    {
        var jsonString = JsonConvert.SerializeObject(ListReferenceData(), new JsonSerializerSettings()
        {
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        });
        await VerifyJson(jsonString);
    }
}

Please see below for a more detailed code.
https://github.com/k-maru/verify_loop_reference

@SimonCropp
Copy link
Member

can u try version 18.0.0-beta.3

@k-maru
Copy link
Author

k-maru commented Aug 22, 2022

@SimonCropp

It worked perfectly! Thank you!

@k-maru k-maru closed this as completed Aug 22, 2022
@SimonCropp SimonCropp added this to the 18.0.0 milestone Aug 22, 2022
@SimonCropp SimonCropp added the Bug label Aug 22, 2022
@SimonCropp
Copy link
Member

@k-maru thanks for closing the loop :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants