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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:55:40+00:00 2026-05-16T04:55:40+00:00

I have a class like this: public class Data { public string Name {

  • 0

I have a class like this:

public class Data
{
    public string Name { get; set; }
    public int Size { get; set; }
    public string Value { get; set; }

    [NonSerialized] public byte[] Bytes;
}

When a List<Data> hits the serialization method below, it occasionally dies with

InvalidOperationException “This
XmlWriter does not support base64
encoded data.”

As you can see, I am not directly encoding anything, just using the default serialization mechanism.

private static XDocument Serialize<T>( T source )
{
    var target = new XDocument( );
    var s = new XmlSerializer( typeof( T ) );
    using( XmlWriter writer = target.CreateWriter( ) )
    {
        s.Serialize( writer, source );
    }
    return target;
}

The data will have Name properties that are English words separated by underscores. The Value property will by similar except with added math operators or numbers (they are mathematical expressions).

Does anyone know what is causing it and how I can correct it?

  • 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-16T04:55:41+00:00Added an answer on May 16, 2026 at 4:55 am

    Use [XmlIgnore] instead of [NonSerialized]. The latter is for the SOAP and binary formatters, according to MSDN:

    When using the BinaryFormatter or
    SoapFormatter classes to serialize an
    object, use the NonSerializedAttribute
    attribute to prevent a field from
    being serialized. For example, you can
    use this attribute to prevent the
    serialization of sensitive data.

    The target objects for the
    NonSerializedAttribute attribute are
    public and private fields of a
    serializable class. By default,
    classes are not serializable unless
    they are marked with
    SerializableAttribute. During the
    serialization process all the public
    and private fields of a class are
    serialized by default. Fields marked
    with NonSerializedAttribute are
    excluded during serialization. If you
    are using the XmlSerializer class to
    serialize an object, use the
    XmlIgnoreAttribute class to get the
    same functionality.

    Mind you, I’m surprised your original code even compiles – when I try it, it says that [NonSerialized] can only be applied to fields…

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

Sidebar

Related Questions

i have a data structure like this public class Employee { public string Name
I have a class like public User class { public string Name{get;set;} public string
I have the following data structure: public class Person { public string Name{get;set;} public
i have code like this public class People { public string name { get;
//class = Person public string Name { get; internal set; } I have an
I have this model : public class Person { public string Name { get;
I have a class like this: public class Contest { List<ContestTeam> Teams { get;
I have a class constructor like this: public JavoImageCorrectedDataHeader() { ByteBuffer buffer = ByteBuffer.allocate(this.size());
I have a base class like this: public class BaseResponse { public string ErrorMessage
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <

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.