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 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

Related Questions

I'm writing a web service which, for each method call, must write a log
I am (just for fun) trying to implement a High Score web-service. I would
Say you are writing an application that must implement the HTTP protocol. Protocols are
Let's say I have to implement a piece of T-SQL code that must return
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
Is it possible to create a WCF service (web service) that only accepts a
Here's the scenario: ASP.NET MVC2 Web Application Entity Framework 4 (Pure POCO's, Custom Data
While creating a simple client for a REST service which I have stubbed out,
I'm looking to build my first web service and I would like to be

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.