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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:42:40+00:00 2026-05-20T02:42:40+00:00

I have a public class that won’t serialize properly. When attempted, the following exception

  • 0

I have a public class that won’t serialize properly. When attempted, the following exception is thrown:

The data contract type ‘MyProject.MyClass’ is not serializable because it is not public. Making the type public will fix this error. Alternatively, you can make it internal, and use the InternalsVisibleToAttribute attribute on your assembly in order to enable serialization of internal members – see documentation for more details. Be aware that doing so has certain security implications.

My class is public, though:

[DataContract]
public class MyClass
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    private int Count;

    public MyClass()
    {
        Name = string.Empty;
        Count = 0;
    }
}

Why am I getting this exception when the class is clearly public?

  • 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-20T02:42:41+00:00Added an answer on May 20, 2026 at 2:42 am

    In Windows Phone 7 apps, you can’t serialize private members:

    Well, it just so happens that WP7 apps run in a “partial trust” environment and outside of “full trust”-land, DataContractSerializer refuses to serialize or deserialize non-public members. Of course that exception was swallowed up internally by .NET so all I ever saw was that bizarre message about things that I knew for certain were public being “not public”. I changed all the private fields I was serializing to public and everything worked just fine.
    http://geekswithblogs.net/mikebmcl/archive/2010/12/29/datacontractserializer-type-is-not-serializable-because-it-is-not-public.aspx

    Changing the code to avoid serializing private members fixes the issue.

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

Sidebar

Related Questions

I have the following collection contract defined: [CollectionDataContract(Name = Centres)] public class Centres :
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a class that looks like this: public class TextField : TextBox {
I have a class that inherits a generic dictionary and an inteface public class
Here is the domain that I wish to have: public class Person { public
If I have a base class such that public abstract class XMLSubscription <T extends
I have a few classes such that: public class XMLStatusMessage extends XMLMessage {} public
I'm building a class library that will have some public & private methods. I
I have a class that contains two methods like these: public String getFoo(Int32 a)
I have an object that is generated in one class public class CreatingClass {

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.