Why has Newtonsoft [JsonIgnore] stopped working in asp core mvc

3927 views asp.net-core

Why is my property with a [JsonIgnore] showing in the returned result?

In fact why are all my Newtonsoft attributes not working?

using Newtonsoft.Json;
using System;

namespace Namespace
    public class Model
        public string IgnoredProperty { get; set; } <-- IS NOT IGNORED

Replacing it with IgnoreDataMember or ScriptIgnore doesn't work?

answered question

1 Answer


It's because asp net core has, since Preview 6, changed which default serializer it uses.

Either change it back by adding .AddNewtonsoftJson() to your MVC options.


Or go to your models and start using the System.Text.Json serializer instead.

 using System.Text.Json.Serialization;
 // using Newtonsoft.Json; <- instead of this

posted this

Have an answer?


Please login first before posting an answer.