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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:40:01+00:00 2026-06-03T15:40:01+00:00

So I have the following method: private int? myIntField [System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)] public int?

  • 0

So I have the following method:

private int? myIntField
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int? IntField{
    get {
        return this.myIntField;
    }
    set {
        this.myIntField= value;
    }
 }

Now, I am deserializing xml from a post, if for whatever reason I am getting a string, such as “here is the int field: 55444” instead of 55444, the error I get in response is: Input string was not in a correct format. which isn’t very specific, especially considering I will have more than one int field I need to verify.

Originally, I was planning something like this:

private string myIntField
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int? IntField{
    get {
        return this.myIntField.CheckValue();
    }
    set {
        this.myIntField= value;
    }
 }

Where CheckValue performs a try-parse to an Int32, and if it fails it returns a null and adds an error to a list. However, I can’t seem to nail this set-up for the generated classes.

Is there I way I can throw a specific error if I am getting strings in place of ints, DateTimes, etc?

  • 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-03T15:40:02+00:00Added an answer on June 3, 2026 at 3:40 pm

    The “Input string was not in a correct format” messages comes from a standard System.FormatException raised by a call to int.Parse, added to the automatically generated assembly that does the deserialization. I don’t think you can add some custom logic to that.

    One solution is to do something like this:

        [XmlElement("IntField")]
        [Browsable(false)] // not displayed in grids
        [EditorBrowsable(EditorBrowsableState.Never)] // not displayed by intellisense
        public string IntFieldString
        {
            get
            {
                return DoSomeConvert(IntField);
            }
            set
            {
                IntField = DoSomeOtherConvert(value);
            }
        }
    
        [XmlIgnore]
        public int? IntField { get; set; }
    

    It’s not perfect, because you can still get access to the public IntFieldString, but at least, the “real” IntField property is used only programmatically, but not by the XmlSerializer (XmlIgnore), while the field that’s holding the value back & forth is hidden from programmers (EditorBrowsable), grids (Browsable), etc… but not from the XmlSerializer.

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

Sidebar

Related Questions

In a public static class I have the following local method: private static int
I have the following serialization method: Private Function SerializeData(ByVal data As cData) As String
I have the following class public class MyClass { private int myAttr; public void
Say you have the following class public class AccessStatistics { private final int noPages,
I have the following function: public class InfrStadium { private InfrStadium(int iTeamId) { _teamId
Let's say I have the following class: class MyClass { private: int Data; public:
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I have following piece of code: class Test{ private: int id; public: Test(int v):id(v)
I have the following method: private static final int OPEN_FOR_RAISE_RANGE = 35; private static
I have the following classes class A{ private String name; private int value; public

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.