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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:23:20+00:00 2026-05-10T17:23:20+00:00

I must implement a web service which expose a list of values (integers, custom

  • 0

I must implement a web service which expose a list of values (integers, custom classes etc). My working solution returns a List<T>, and according to FxCop it is better to return a Collection<T> or ReadOnlyCollection<T>.

If I choose to return a ReadOnlyCollection<T>, the web service shows an error like:

To be XML serializable, types which inherit from ICollection must have an implementation of Add(System.Int32) at all levels of their inheritance hierarchy. System.Collections.ObjectModel.ReadOnlyCollection 1 [[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] does not implement Add(System.Int32).

What is your favorite way to use internally a List<T> and expose a Collection<T> ? (using C#, and preferably framework 2.0 only)

  • 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. 2026-05-10T17:23:20+00:00Added an answer on May 10, 2026 at 5:23 pm

    List<T> or Collection<T> are fine in this case.

    In terms of the original question, you can wrap a List<T> in a Collection<T> very simply:

    List<Foo> list = new List<Foo>(); // ... Collection<Foo> col = new Collection<Foo>(list); 

    This is a true wrapper; add an item to the wrapper (col), and it gets added to the list. This can be slightly confusing, because many such constructors use the argument to do the initial population, but don’t link to the original list. Collection<T> is an exception ;-p

    Since you are on a web-service boundary, that recommendation from FxCop doesn’t apply. That is useful (inline with Eric Lippert’s recent blog) to prevent a caller stomping over the callee’s memory – but in a web-service distributed scenario that simply doesn’t apply. In fact, since web-services have a few well documented issues with certain generic scenarios, a simple array is arguably very usable and pragmatic at a web-service boundary. In the context of Eric’s blog – in this case, there is no question of the caller/callee issue, since there is an enforced barrier between the two.

    In terms of WSDL/mex, I suspect all 3 (list/collection/array) will just become a block of elements – so you may a well go with whichever is most convenient.

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

Sidebar

Ask A Question

Stats

  • Questions 280k
  • Answers 280k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It sounds like the wrong identify command (which is part… May 13, 2026 at 3:44 pm
  • Editorial Team
    Editorial Team added an answer Python threads will all die with Python. Also, os.system is… May 13, 2026 at 3:44 pm
  • Editorial Team
    Editorial Team added an answer A comment is a special node in DOM. See the… May 13, 2026 at 3:44 pm

Related Questions

I've read a lot of books on software design, and more and more I'm
I have a Windows Service which performs a certain function, and then needs to
The Amazon Product Advertising API (formerly Amazon Associates Web Service or Amazon AWS) has
I am getting this error message when I try to Add Web Reference to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.