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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:37:02+00:00 2026-05-19T00:37:02+00:00

I have this little method in a class library that is held in an

  • 0

I have this little method in a class library that is held in an external dll, away from the “client” app.

    public void SaveToDisk()
    {
        // Create a storage container and save
        // this instance to it. Use "this" storage name.
        var settingsToStore = this;
        var settings = IsolatedStorageSettings.ApplicationSettings;
        settings[StorageName] = settingsToStore;
        settings.Save();
    }

Essentially it stores itself to the phones isolated storage. The class that contains this is not marked with any attributes. The error I get is this:

ex {“Type ‘CabbageWrapper.Account’
cannot be serialized. Consider marking
it with the DataContractAttribute
attribute, and marking all of its
members you want serialized with the
DataMemberAttribute
attribute.”} System.Exception
{System.Runtime.Serialization.InvalidDataContractException}

I would like to know what the error means rather than just adding attributes and praying that this works. Thanks!

EDIT: As requested, class in full.

using System.IO.IsolatedStorage;

public class Account
{

    public string Provider { get; private set; }

    public string ServerSymbol { get; private set; }

    public int MessageCharAllowance { get; private set; }

    public int RemainingWebtextAllowance { get; set; }

    public int WebtextAllowance { get; private set; }

    public string Username { get; private set; }

    public string Password { get; private set; }

    public string StorageName { get; private set; }

    public Account(string provider, string storageName, string username, string password)
    {
        // Assign the values to "this" instance.
        Provider = provider;
        Username = username;
        Password = password;
        StorageName = storageName;

        // Load the ServerSymbol and WebtextAllowance from
        // the libraries resources. These are known values.
        PopulateKnownData();

        // Save to disk
        SaveToDisk();
    }


    public Account(string storageName)
    {
        // We need to know the name of the storage 
        // container to perform the load. Get it
        // from the caller and save it to "this" instance.
        StorageName = storageName;

        // Perform the load.
        LoadFromDisk();
    }


    private void PopulateKnownData()
    {
        switch (Provider)
        {
            case "Vodafone":
                ServerSymbol = "v";
                WebtextAllowance = 600;
                RemainingWebtextAllowance = -1;
                break;

            case "O2":
                ServerSymbol = "o";
                WebtextAllowance = 250;
                RemainingWebtextAllowance = -1;
                break;

            case "Meteor":
                ServerSymbol = "m";
                WebtextAllowance = 250;
                RemainingWebtextAllowance = -1;
                break;

            case "Three":
                ServerSymbol = "t";
                WebtextAllowance = 333;
                RemainingWebtextAllowance = -1;
                break;

            default:
                break;
        }
    }


    public void LoadFromDisk()
    {
        // Create a dummy account for rehydration and
        // use it to grab the stored account from memory.
        Account storedAccount;
        IsolatedStorageSettings.ApplicationSettings.TryGetValue(StorageName, out storedAccount);

        // Use the stored details to hydrate this instance.
        Provider = storedAccount.Provider;
        ServerSymbol = storedAccount.ServerSymbol;
        RemainingWebtextAllowance = storedAccount.RemainingWebtextAllowance;
        WebtextAllowance = storedAccount.WebtextAllowance;
        MessageCharAllowance = storedAccount.MessageCharAllowance;
        Username = storedAccount.Username;
        Password = storedAccount.Password;
    }


    public void SaveToDisk()
    {
        // Create a storage container and save
        // this instance to it. Use "this" storage name.
        var settingsToStore = this;
        var settings = IsolatedStorageSettings.ApplicationSettings;
        settings[StorageName] = settingsToStore;
        settings.Save();
    }
}
  • 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-19T00:37:03+00:00Added an answer on May 19, 2026 at 12:37 am

    The exception message is pretty self-explanatory. By decorating members with these attributes, you tell serializer what items are serialized (most of the time you want serialize only some members, not everything in your class). The reason why you must define them is simply that you can decide what to serialize and what not. There are also performance, security etc considerations, so this is reason why it’s not done by default. Read http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.aspx “Apply the DataContractAttribute attribute to classes, and the DataMemberAttribute attribute to class members to specify properties and fields that are serialized. “

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

Sidebar

Related Questions

I have this little bit of code: using System; using System.Web.Mvc; public class SecureFilter
I have a C# class library that contains methods that need to be used
Within a class library I'm writing I have a method allowing the library to
I have this method in a class I am using def binary_search(a,x) # ...
If I have a generic class like this: public class Repository<T> { public string
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
I have this little script to toggle a contact form when a button is
I've searched for this a little but I have not gotten a particularly straight
This is a little out there but I have a customer object coming back
I need a little help on this subject. I have a Web application written

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.