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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T13:00:51+00:00 2026-05-22T13:00:51+00:00

I have a class that takes standard address properties and stores them. The State

  • 0

I have a class that takes standard address properties and stores them. The State property is of type USStateCodesType. Here’s a sample of the code used to store the properties:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://SP/Items/Schemas")]
public partial class BusinessAddress
{

    private string address1Field;

    private string address2Field;

    private string cityField;

    private USStateCodesType stateField;

    private bool stateFieldSpecified;

    private string zipField;

    /// <remarks/>
    public string Address1
    {
        get
        {
            return this.address1Field;
        }
        set
        {
            this.address1Field = value;
        }
    }

The USStateCodesType contains a private dictionary with a string key and value. The default constructor loads up the dictionary and is called by any overloads. There is only one public Property, State. It is coded as follows:

    public string State
    {
        get
        {
            return iDict[_key];
        }
        set
        {
            if (iDict.ContainsValue(value))
            {
                foreach (string k in iDict.Keys)
                    if (iDict[k] == value)
                        _key = k;
            }
            else
                _key = string.Empty;                    
        }
    }

The attributes above the USStatesCodeType are identical to the earlier example.

The problem is, when I try to serialize the object to an XML String, i get something like this:

  <BusinessAddress>
    <Address1>12345 AnyStreet</Address1>
    <City>Los Angles</City>
    <Zip>90210</Zip>
  </BusinessAddress>

In my Database, I am storing CA. I want the XML to put out

  <BusinessAddress>
    <Address1>12345 AnyStreet</Address1>
    <City>Los Angles</City>
    <State>California</State>
    <Zip>90210</Zip>
  </BusinessAddress>

I check the properties of the object prior to serialization and the State Property shows California as the value.

What am I doing wrong?

  • 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-22T13:00:52+00:00Added an answer on May 22, 2026 at 1:00 pm

    I would assume that you created an instance of BusinessAddress and specified the various properties:

    BusinessAddress myBusinessAddress = new BusinessAddress();
    myBusinessAddress.Address1 = "12345 AnyStreet";
    myBusinessAddress.City = "Los Angeles";
    myBusinessAddress.Zip = 90210;
    myBusinessAddress.State = "California";
    

    but most likely, you didn’t specify:

    myBusinessAddress.StateFieldSpecified = true;
    

    If you forget that option, your State field will not show up in the resulting serialized XML.

    Set that boolean property, and it will show up!

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

Sidebar

Related Questions

I have a generic class that takes a type T . Within this class
I am creating unit tests with DUnit. I have a class that takes quite
I have a class with two constructors, one that takes no arguments and one
So I have a base class with a constructor that takes (T V) .
I have a Login Class which has a function: isCorrect() that takes username and
I have a method that takes a list of entities ( Class es) and
I have a static method that takes a parameter and returns a class. the
I want to have a class property that allow for an expression to take
I have a program in python that includes a class that takes a function
I have a master class: A with a constructor that takes an optional login

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.