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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:22:22+00:00 2026-06-11T17:22:22+00:00

I have a piece of code which uses the datacontract serializer to serialize and

  • 0

I have a piece of code which uses the datacontract serializer to serialize and deserialize to/from an .xml file. One of the public property is an enumeration. There is a probability that .xml will be edited by hand and then it is a possible that property which is an enumeration may have some value which is not part of the enumeration. In this case the datacontract fails while deserailizing.

How can this be handled ? What is a good solution ?

  • 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-11T17:22:23+00:00Added an answer on June 11, 2026 at 5:22 pm

    Try this:

    public enum E
    {
        One, 
        Two
    }
    
    [DataContract]
    public class C
    {
        [DataMember]
        private string myField;
    
        public E MyProperty 
        {
            get 
            { 
                E result;
                return Enum.TryParse<E>(myField, out result) ? result : default(E);
            }
            set { myField = value.ToString(); }
        }
    }
    

    Since the user can put anything into corresponding XML tag, then I can’t see best solution, than store property value in the string field.

    If performance is critical, you can store enum value in regular property, and work with string field only when serializing/deserializing data (see OnSerializingAttribute/OnDeserializedAttribute).

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

Sidebar

Related Questions

I have some code which uses System.Net.Mail.SmtpClient.Send to send data from a piece of
I have this piece of code which check the last customer_id from the db.
I have a piece of code which returns a Sales Order from AX. In
I have created a piece of code which takes an IP address (from main
Ok i have this piece of code from which i took from W3schools :-
I have a piece of matlab code below which reads data from a table.
I have the following piece of code which uses ICU macros in order to
I have the following piece of code which uses the ALAssets library to store
I have found the following piece of code which uses XmlHttpRequest to read JSON
I have written a piece of code which uses the PdfSharp library. The instance

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.