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 713597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:58:45+00:00 2026-05-14T04:58:45+00:00

I have a class Team that holds a generic list: [DataContract(Name = TeamDTO, IsReference

  • 0

I have a class Team that holds a generic list:

[DataContract(Name = "TeamDTO", IsReference = true)]
public class Team
{
    [DataMember]
    private IList<Person> members = new List<Person>();

    public Team()
    {
        Init();
    }

    private void Init()
    {
        members = new List<Person>();
    }

    [System.Runtime.Serialization.OnDeserializing]
    protected void OnDeserializing(StreamingContext ctx)
    {
        Log("OnDeserializing of Team called");
        Init();
        if (members != null) Log(members.ToString());
    }

    [System.Runtime.Serialization.OnSerializing]
    private void OnSerializing(StreamingContext ctx)
    {
        Log("OnSerializing of Team called");
        if (members != null) Log(members.ToString());
    }

    [System.Runtime.Serialization.OnDeserialized]
    protected void OnDeserialized(StreamingContext ctx)
    {
        Log("OnDeserialized of Team called");
        if (members != null) Log(members.ToString());
    }

    [System.Runtime.Serialization.OnSerialized]
    private void OnSerialized(StreamingContext ctx)
    {
        Log("OnSerialized of Team called");
        Log(members.ToString());
    }

When I use this class in a WCF service, I get following log output

OnSerializing of Team called    
System.Collections.Generic.List 1[XXX.Person]

OnSerialized of Team called    
System.Collections.Generic.List 1[XXX.Person]

OnDeserializing of Team called    
System.Collections.Generic.List 1[XXX.Person]

OnDeserialized of Team called    
XXX.Person[]

After the deserialization members is an Array and no longer a generic list although the field type is IList<> (?!)
When I try to send this object back over the WCF service I get the log output

OnSerializing of Team called
XXX.Person[]

After this my unit test crashes with a System.ExecutionEngineException, which means the WCF service is not able to serialize the array. (maybe because it expected a IList<>)

So, my question is: Does anybody know why the type of my IList<> is an array after deserializing and why I can’t serialize my Team object any longer after that?

Thanks

  • 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-05-14T04:58:45+00:00Added an answer on May 14, 2026 at 4:58 am

    You’ve run into one of the DataContractSerializer gotchas.

    Fix: Change your private member declaration to:

    [DataMember]
    private List<Person> members = new List<Person>();
    

    OR change the property to:

    [DataMember()]
    public IList<Person> Feedback {
        get { return m_Feedback; }
        set {
            if ((value != null)) {
                m_Feedback = new List<Person>(value);
    
            } else {
                m_Feedback = new List<Person>();
            }
        }
    }
    

    And it will work. The Microsoft Connect bug is here

    This problem occurs when you deserialize an object with an IList<T> DataMember and then try to serialize the same instance again.

    If you want to see something cool:

    using System;
    using System.Collections.Generic;
    
    class TestArrayAncestry
    {
        static void Main(string[] args)
        {
            int[] values = new[] { 1, 2, 3 };        
            Console.WriteLine("int[] is IList<int>: {0}", values is IList<int>);
        }
    }
    

    It will print int[] is IList<int>: True.

    I suspect this is possibly the reason you see it come back as an array after deserialization, but it is quite non-intuitive.

    If you call the Add() method on the IList<int> of the array though, it throws NotSupportedException.

    One of those .NET quirks.

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

Sidebar

Related Questions

I have 3 model classes: class Team(models.Model): name = models.CharField(max_length=100, default=, blank=True, null=True) number
I have class with back reference: public class Employee : Entity { private string
I have class with collection as below public class MyClass:IXmlSerializable { int vesrion; private
I have a class team that contains information for football teams. I need to
This is the datamodel I have: public class Team { [Key] public int Id
i have a class Team.as that imports another class CustomMenu.as . This works fine,
Our team is currently developing a web application, in that we have a class
We have a class hierarchy similar to this one: public class TestDereference { private
Say I have a model like: class Team(models.Model): name = models.CharField(max_length=20) class Game(models.Model): title
I have a one way @OneToMany relationship between a Team and Player class. I

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.