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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:30:27+00:00 2026-05-30T17:30:27+00:00

whenever I try to serialize an object that has an IEnumerable collection I get

  • 0

whenever I try to serialize an object that has an IEnumerable collection I get a big dirty error telling me it can’t serialize it because it’s an interface. Now I get why it’s happening but it raises some other questions for me. Like if I intend on having collections within my objects AND I want to serialize them do I need to resort to

  1. Using List<>, CollectionBase, ReadOnlyCollectionBase in my objects.
  2. Making my objects implement the IXmlSerializable interface.
  3. Decorating my classes with horrible attributes.
  4. Writing my own serializer.

What is the best practice way to go?

  • 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-30T17:30:28+00:00Added an answer on May 30, 2026 at 5:30 pm

    Speaking as a serializer author, I know exactly why it gets very hard to robustly work just from IEnumerable<T>, especially for “get-only” properties. You might try IList<T> (although it wouldn’t amaze me if it wants a concrete type such as List<T>/T[]), but I suspect the real problem here is that you trying to use one model to do two things, and are unhappy at having to compromise to do it.

    Fine: if you don’t want to compromise your domain model, write a separate DTO model that is used for serialization, and just map between them. This is usually trivial, and will allow the serializer and the domain model to each excel at their one job. It will also help immensely when you need to “version” the system or introduce a different serializer (JSON, protobuf, etc).

    Re your bullets:

    • I suspect any concrete list type (even your own) with Add etc will work
    • I don’t recommend that to anyone – it is painful to do reliably
    • nothing ugly about attributes; again, I suspect your complaint is about attributing your domain model – so: fine, don’t do that – have a separate model; you can actually do all this at runtime, but it is much more work (see XmlAttributeOverrides, but watch out for leaking assemblies if you do this)
    • don’t underestimate how much work that is; the basics – seductively easy; but the non-trivial scenarios can be brutal
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

whenever I try to call my ejb from a client, I get this error
I get the above error whenever I try and use ActionLink ? I've only
Why is it that I can never get JQuery serialize to work properly. I
Whenever I try to upload a sound file IO get the error The connection
whenever I try to install Rails on windows7 , I get the error, File
Whenever I try to copy a file that's bigger than 2GB, I get an
Whenever I try to install a Click Once application, I always get a 404
Whenever i try to run sqlmetal, i get this: 'sqlmetal' is not recognized as
Visual Studio Team system 2008 crashes without any error messages whenever I try to
I'm trying create a ASMX webservice that can perform a HTTP GET request. 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.