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

  • Home
  • SEARCH
  • 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 8839415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:13:57+00:00 2026-06-14T10:13:57+00:00

I have a wrapped list that looks like this: [JsonObject(MemberSerialization.Fields)] public class OrderManager :

  • 0

I have a wrapped list that looks like this:

[JsonObject(MemberSerialization.Fields)]
public class OrderManager : IEnumerable<Order>, ISerializable
{
    public OrderManager()
    { }

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

    public void AddOrder(OrderInfo orderInfo)
    {
        // do the work of making an order object from an OrderInfo.
        // Add the new order object to the private list of orders
        // orders.Add(order);
    }

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

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

    public OrderManager(SerializationInfo info, StreamingContext context)
    {
        // do custom serialization work here (never gets hit)
    }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        // do custom serialization work here (never gets hit)
    }
}

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

[JsonObject(MemberSerialization.Fields)]
public class Customer
{
    public Customer()
    { }

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

I can serialize a customer but the ISerializable interface on OrderManager is ignored. If I remove the JsonObject attribute from the OrderManager (probably what is preventing ISerializable from being used) the OrderManager is treated as an array and the ISerializable interface is still ignored.

I tried using ICollection instead of IEnumerable:
JSON.NET cannot deserialize a wrapped collection

Since my wrapped collection is of type Order and my AddOrder method takes in OrderInfo, it doesn’t really work to expose ICollection<Order>. Either way, the ISerializable interface was ignored.

Are there any workarounds?

Update

Just to clarify I do have IgnoreSerializableInterface set to false.

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

    serializer.TypeNameHandling = TypeNameHandling.Auto;
    serializer.TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;

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

    serializer.ContractResolver = contractResolver;

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

    return serializer;          
}
  • 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-14T10:13:58+00:00Added an answer on June 14, 2026 at 10:13 am

    This answer might be late but:

    This is because it checks for inheritance of IEnumerable before checking for inheritance of ISerializable so it will use the Enumerable interface to pull objects out first.

    You can override this behavior by implementing your own contract resolver inheriting from DefaultContractResolver with this override:

        protected override JsonContract CreateContract(Type objectType)
        {
            if (typeof(ISerializable).IsAssignableFrom(objectType))
                return CreateISerializableContract(objectType);
    
            return base.CreateContract(objectType);
        }
    

    Preferably with some better logic, but this at the root will cause objects that implement ISerializable and IEnumerable to use the ISerializable implementation first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wrapped list that looks like this: [Serializable] public class OrderManager :
I'm trying to build an object that looks something like this: public class MyObject
I have a service contract interface that looks like this: [ServiceKnownType(typeof(GeometricModelDescriptor))] [ServiceKnownType(typeof(TemplateModelDescriptor))] [ServiceContract] public
I have some images that are wrapped within containers like this: <div id=swatchcontainer> <div
If i have a ViewModel like this: public class MyViewModel { [UIHint(SomeTemplate)] public ICollection<SomeViewModel>
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
I have: @Component class MyDecorator{ private Cache cache; /* some wrapped methods like get
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

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.