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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:39:11+00:00 2026-05-14T19:39:11+00:00

For our Silverlight Project (SL4) I’m using a Model which might contain Lists (

  • 0

For our Silverlight Project (SL4) I’m using a Model which might contain Lists (IList<AnotherModel>). According to good practice and rule CA2227:CollectionPropertiesShouldBeReadOnly
the IList properties don’t have a public setter. We serialize the Model using the DataContractSerializer which is working. But when I try to deserialize, a SecurityException is thrown by DataContractSerializer’s ReadObject(Stream) Method, complaining that the target property (pointing to the IList property) cannot be set due to a missing public setter.

Since the DataContractSerializer is sealed and neither extendable nor flexible so I currently see no chance to add some kind of additional rules which allow to deserialize the ILists using a foreach-loop on Add() method or some other method of transferring the collection items.

I’ve also tried to dig into DataContractSerializer source (using Reflector) to create a little fork but it looks like i’d have to dig very deep and replicating whole serialization classes doesn’t seem to be a viable solution.

Do you see another chance to serialize a List with no public setter using the DataContractSerializer?

Thank you very much in advance for your ideas!


UPDATE
Solved using XmlSerializer.


Thomas

  • 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-14T19:39:12+00:00Added an answer on May 14, 2026 at 7:39 pm

    In our case, we found out that we were not strictly bound to the DataContractSerializer, and interestingly, the XmlSerializer DOES support serialization of read-only ILists! In fact, it even doesn’t allow a public setter for the IList interface in this case (cannot deserialize interface property) but (de-)serializing the ILists items works like a charm.

    Only change for us was adding [XmlInclude] attributes in addition to [KnownType] (and of course, replacing the few lines from DataContractSerializer.WriteObject(...) to XmlSerializer.Serialize(...).

    Thanks for your support! =)

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

Sidebar

Related Questions

We are using Oracle 10g database, NHibernate, WCF and Silverlight 3.0 in our project
We're using silverlight on our SharePoint site. When someone navigates to the page containing
My team is building our first significant Silverlight application, using a 3 layered architecture
I'm looking at using Silverlight to create a multi-file uploader for one of our
I have got an error while trying to upgrade our large project to SL4.
I have a complex project using SilverLight Toolkit's ListBoxDragDropTarget for drag-drop operations and it
We are embarking on our first Silverlight project, coming from WPF. It's a relatively
An upcoming project at work looks like it might involve Silverlight. We're a .NET
In our Silverlight 2 project we have created an attached property to perform on-the-fly
We are using MVVM Light Silverlight project for WCF Ria Service based project. After

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.