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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:16:18+00:00 2026-05-12T05:16:18+00:00

I appear to be having an issue with the following snippet of code in

  • 0

I appear to be having an issue with the following snippet of code in that, when I come to specifying what the Item is (eg CashInHand), the actual type CashInHandPayment is not available because it hasn’t been carried across when I generate the proxy class (most likely because it doesn’t read in XmlElementAttributes).

Is there any way to force classes such as AccountPayment, CashInHandPayment and CCPayment to be serialized in the proxy class?

[DataContract]
public class Payment
{
    [XmlElementAttribute("Account", typeof(AccountPayment))]
    [XmlElementAttribute("CashInHand", typeof(CashInHandPayment))]
    [XmlElementAttribute("CreditCard", typeof(CCPayment))]
    [XmlChoiceIdentifierAttribute("ItemElementName")]
    [DataMember]
    public object Item { get; set; }
}

[DataContract]
public enum ItemElementName
{
    [EnumMember]
    Account,
    [EnumMember]
    CashInHand,
    [EnumMember]
    CreditCard
}

//This class will not be in the generated proxy class
[DataContract]
public class AccountPayment
{
    [DataMember]
    public double Amount { get; set; }
}

//classes for CashInHandPayment and CCPayment also created, but not shown.

Forgive me if ‘serialize’ isn’t the correct term to use, if you read the question and find that it isn’t, please change it accordingly!

Update – answer mentioned by Simon Svensson:

[KnownType(typeof(AccountPayment))]
[KnownType(typeof(CashInHandPayment))]
[KnownType(typeof(CCPayment))]
[DataContract]
public class Payment
{
    [XmlElementAttribute("Account", typeof(AccountPayment))]
    [XmlElementAttribute("CashInHand", typeof(CashInHandPayment))]
    [XmlElementAttribute("CreditCard", typeof(CCPayment))]
    [XmlChoiceIdentifierAttribute("ItemElementName")]
    [DataMember]
    public object Item { get; set; }
}

Many thanks, Simon!

  • 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-12T05:16:19+00:00Added an answer on May 12, 2026 at 5:16 am

    Uhm. Isnt XmlElementAttribute and XmlChoiceIdentifierAttribute xml serialization, which is a older serialization compared to the DataContractSerializer which reads DataContractAttribute and DataMemberAttribute?

    I believe that you should use the KnownTypeAttribute for this, but I have never tried it, nor have I had this scenario in my own code.

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

Sidebar

Related Questions

I'm having an issue with the following code. A yellow border should appear around
Hi am having a annoying issue.Look at the following code, In the code I
Using Internet Explorer (don't appear to have an issue in FireFox) the following code
On the following page: http://jsfiddle.net/3h7pL/ I'm having an issue where the submenu isn't showing
I am having an issue positioning a background image using the following jquery background
I am having a weird issue in ASP.NET MVC with objects not being updated
I am having a small issue converting some C# code to VB.NET. I am
I am having an issue trying to scroll the browser window immediately following jQuery
LIVE CODE: http://jsfiddle.net/vy4nY/ I'm following this challenge , but I'm having some issues. I'm
I'm currently having the following issue in my project: I'm using Core Data to

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.