Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7898141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:21:12+00:00 2026-06-03T08:21:12+00:00

I have a wrapped list that looks like this: [Serializable] public class OrderManager :

  • 0

I have a wrapped list that looks like this:

[Serializable]
public class OrderManager : IEnumerable<Order>
{
    public OrderManager()
    { }

    private List<Order> orders = new List<Order>();

    public void AddOrder(Order order)
    {
        orders.Add(order);
    }

    public IEnumerator<Order> GetEnumerator()
    {
        return orders.GetEnumerator();
    }

    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
    {
        return orders.GetEnumerator();
    }
}

I include a field instance in a customer class like this:

[Serializable]
public class Customer
{
    public Customer()
    { }

    private OrderManager _orders
        = new OrderManager();
    public OrderManager Orders
    {
        get { return _orders; }
        set { _orders = value; }
    }
}

I create the JSON.NET serializer like this:

private JsonSerializer GetSerializer()
{
    var serializer = new JsonSerializer();

    // on or off the type name handling doesn't help
    //serializer.TypeNameHandling = TypeNameHandling.All;

    var contractResolver = new DefaultContractResolver(true);
    contractResolver.IgnoreSerializableAttribute = false;
    contractResolver.IgnoreSerializableInterface = false;

    serializer.ContractResolver = contractResolver;

    serializer.PreserveReferencesHandling = PreserveReferencesHandling.All;
    serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

    return serializer;          
}

Serialization of a customer object works, but during deserialization I get the error:

Error setting value to ‘_orders’ on
‘Tests.SerializationTests+Customer’.

With TypeNameHandling set to All I get this:

Type specified in JSON 'Tests.SerializationTests+Order[], Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not compatible with 'Tests.SerializationTests+OrderManager, Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Path '_orders.$type', line 1, position 232.

Any idea how to get Json.NET to play nice with the wrapped list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:21:13+00:00Added an answer on June 3, 2026 at 8:21 am

    I guess you need to implement ICollection<Order>

    public class OrderManager : IEnumerable<Order>,ICollection<Order>
    

    –

    [Serializable]
    public class OrderManager : IEnumerable<Order>,ICollection<Order>
    {
        public OrderManager()
        { }
    
        private List<Order> orders = new List<Order>();
    
        public Order this[int i]
        {
            set { AddOrder(value); }
            get { return orders[i]; }
        }
    
        public void AddOrder(Order order)
        {
            orders.Add(order);
        }
    
        public IEnumerator<Order> GetEnumerator()
        {
            return orders.GetEnumerator();
        }
    
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return orders.GetEnumerator();
        }
    
        public void Add(Order item)
        {
            AddOrder(item);
        }
    
        public void Clear()
        {
            orders.Clear();
        }
    
        public bool Contains(Order item)
        {
            return orders.Contains(item);
        }
    
        public void CopyTo(Order[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }
    
        public int Count
        {
            get { return orders.Count; }
        }
    
        public bool IsReadOnly
        {
            get { return false; }
        }
    
        public bool Remove(Order item)
        {
            return orders.Remove(item);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to build an object that looks something like this: public class MyObject
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
I have a renderer that looks like this: <s:ItemRenderer xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx autoDrawBackground=true> <s:Group
If i have a ViewModel like this: public class MyViewModel { [UIHint(SomeTemplate)] public ICollection<SomeViewModel>
I need Xml that looks like this <foo> <bar ... /> <bar ... />
I have 3 gits wrapped by a manifest file (this manifest file is in
I'd like to center a list of left-aligned items. This is what I currently
I have often wrapped block level elements with <a> tags in order to make
I have a DataGridView bound on a generic list, in .NET 3.5. When this
I have an options button that, when clicked on, will display a dropdown list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.