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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:13:50+00:00 2026-06-17T18:13:50+00:00

I am trying to Serialize an ObservableCollection. But I am getting following error: Let

  • 0

I am trying to Serialize an ObservableCollection. But I am getting following error: Let me know how can I fix this?

Error:

{System.InvalidOperationException: There was an error reflecting type
‘System.Collections.ObjectModel.ObservableCollection1[eText.DataModel.BooksDownloadedData]'.
---> System.InvalidOperationException: There was an error reflecting type 'eText.DataModel.BooksDownloadedData'. --->
System.InvalidOperationException: Cannot serialize member
'eText.DataModel.BooksDownloadedData.DownloadedBookFileDetails' of
type 'Windows.Storage.StorageFile', see inner exception for more
details. ---> System.InvalidOperationException:
Windows.Storage.StorageFile cannot be serialized because it does not
have a parameterless constructor. --- End of inner exception stack
trace --- at
System.Xml.Serialization.StructModel.CheckSupportedMember(TypeDesc
typeDesc, MemberInfo member, Type type) at
System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo
propertyInfo) at
System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo
memberInfo) at
System.Xml.Serialization.XmlReflectionImporter.InitializeStructMembers(StructMapping
mapping, StructModel model, Boolean openModel, String typeName,
RecursionLimiter limiter) at
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel
model, String ns, Boolean openModel, XmlAttributes a, RecursionLimiter
limiter) at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType,
XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter
limiter) --- End of inner exception stack trace --- at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType,
XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter
limiter) at
System.Xml.Serialization.XmlReflectionImporter.CreateArrayElementsFromAttributes(ArrayMapping
arrayMapping, XmlArrayItemAttributes attributes, Type
arrayElementType, String arrayElementNs, RecursionLimiter limiter)
at
System.Xml.Serialization.XmlReflectionImporter.ImportArrayLikeMapping(ArrayModel
model, String ns, RecursionLimiter limiter) at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType,
XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter
limiter) --- End of inner exception stack trace --- at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType,
XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter
limiter) at
System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel
model, XmlRootAttribute root, String defaultNamespace,
RecursionLimiter limiter) at
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type
type, XmlRootAttribute root, String defaultNamespace) at
System.Xml.Serialization.XmlSerializer..ctor(Type type, String
defaultNamespace) at
System.Xml.Serialization.XmlSerializer..ctor(Type type) at
eText.Common.Xml.Serialize[T](Object obj, Type[] extraTypes) in
f:\TFS\New
TFS\PDFReader\Posh.PdfReader.Win8\eText\Common\Utility.cs:line 81
at
eText.Common.ApplicationSettings.<SaveDataToFileAsync>d__0
1.MoveNext()
in f:\TFS\New
TFS\PDFReader\Posh.PdfReader.Win8\eText\Common\ApplicationSettings.cs:line
16
— End of stack trace from previous location where exception was thrown — at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at eText.ViewModel.MainViewModel.d__a.MoveNext() in
f:\TFS\New
TFS\PDFReader\Posh.PdfReader.Win8\eText\ViewModel\MainViewModel.cs:line
268}

Code That I am using to serialize:

Book Class:

[DataContract] 
public class Book : ViewModelBase
{
    #region Constructor

    /// <summary>
    /// Initializes a new instance of the <see cref="Book" /> class.
    /// </summary>
    public Book(){}

    /// <summary>
    /// Initializes a new instance of the <see cref="Book" /> class.
    /// </summary>
    /// <param name="BookTitle">The book title.</param>
    /// <param name="BookCategory">The book category.</param>
    /// <param name="DownloadURL">The download URL.</param>
    /// <param name="TotalNumberOfPages">The total number of pages.</param>
    /// <param name="BookAuthor">The book author.</param>
    /// <param name="ImageURL">The image URL.</param>
    public Book(string BookTitle,string BookCategory,string DownloadURL, string TotalNumberOfPages, string BookAuthor, string ImageURL)
    {
        this.BookCategory = BookCategory;
        this.BookTitle = BookTitle;
        this.BookAuthor = BookAuthor;
        this.TotalNumberOfPages = TotalNumberOfPages;
        this.DownloadURL = DownloadURL;
        this.ImageURL = ImageURL;
    }

    #endregion    
}

BooksDownloadedData class

 /// <summary>
    /// Class to store downloaded books metaData
    /// </summary>
    [DataContract] 
    public class BooksDownloadedData
    {

        /// <summary>
        /// The downloaded books detail
        /// </summary>
        [DataMember]
        public Book DownloadedBooks { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is downloaded completed.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is downloaded completed; otherwise, <c>false</c>.
        /// </value>
       [DataMember]
        public bool IsDownloadedCompleted { get; set; }
}

Created an ObservableCollection for BooksDownloadedData and then saving it in Local Storage after serializing but at time of serializing getting error:

// Create object to get the saved meta data of files
  ObservableCollection<BooksDownloadedData> downLoadedFiles;

 // Save the data to the local storage
                await ApplicationSettings.SaveDataToFileAsync<ObservableCollection<BooksDownloadedData>>(fileName, downLoadedFiles);

 public static async Task SaveDataToFileAsync<T>(string key, T value, bool roaming = false, Type[] extraTypes = null)
        {
            var file = roaming ? await ApplicationData.Current.RoamingFolder.CreateFileAsync(key + ".xml", CreationCollisionOption.ReplaceExisting) :
                await ApplicationData.Current.LocalFolder.CreateFileAsync(key + ".xml", CreationCollisionOption.ReplaceExisting);

            var xml = Xml.Serialize<T>(value, extraTypes);
            await FileIO.WriteTextAsync(file, xml, UnicodeEncoding.Utf8);
        }

 public static string Serialize<T>(object obj, Type[] extraTypes = null)
        {
            using (var sw = new StringWriter())
            {
                var serializer = extraTypes == null ? new XmlSerializer(typeof(T)) : new XmlSerializer(typeof(T), extraTypes);
                serializer.Serialize(sw, obj);
                return sw.ToString();
            }
        }
  • 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-06-17T18:13:52+00:00Added an answer on June 17, 2026 at 6:13 pm

    The problem is the use of Windows.Storage.StorageFile, which clearly isn’t intended to play nicely with serialization (or at least: not XmlSerializer).

    You might be able to refactor your model so that you don’t need to use StorageFile. You might be able to mark that member (DownloadedBookFileDetails) with [XmlIgnore], and re-create the StorageFile manually after deserialization. You might be able to use a different serializer (DataContractSerializer, JSON.NET, protobuf-net, etc).

    However! In most cases I see (and I deal with serialization a lot) the key mistake people make is trying to fight the serializer so that they can keep using their existing domain model. When actually, the simplest thing to do is usually: create a DTO: a separate model that is designed solely to represent the data as a bridge to serialization, and then map to/from the DTO model and your main domain model.

    Not only does this invariably work really easily every time, it also puts you in a very strong position if you ever want to:

    • revise the domain model without affecting serialized data (you only tweak the mapping)
    • add a separate version / API that has a different layout (public vs private APIs, maybe)
    • use a different serializer (in addition, or instead of)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I'm trying serialize a class containing this property: [NonSerialized] property System::Collections::ObjectModel::ReadOnlyCollection<String^>^ IgnoredWords I
I'm trying to serialize and deserialize this ObservableCollection: public class DataCollection : ObservableCollection<Data> {
I'm trying to serialize an object and the following SerializationException is thrown: Type 'System.Linq.Enumerable+d__71`1[[System.String,
Trying to serialize and send Lot object to socket. Getting error: java.io.NotSerializableException: com.server.ClientServiceThread Why?
I have been trying to serialize a pretty big object. This object uses dictionaries
I'm trying to serialize a Type object in the following way: Type myType =
I am trying to serialize a list of descendants. This is what I have
I am trying to serialize something based upon meeting particular criteria. To this end
I'm trying to serialize some data for a UDP packet stream and I'm getting
I'm trying to serialize a Doctrine_query object in Symfony : var_dump(serialize($this->pager->getQuery())); The result is

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.