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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:03:06+00:00 2026-05-21T11:03:06+00:00

To start: This is also for REST deserialiaztion, so a custom XmlSerializer is out

  • 0

To start: This is also for REST deserialiaztion, so a custom XmlSerializer is out of the question.

I have a hjierarchy of classes that need to be serializable and deserializable from an “Envelope”. It has an arrayelement named “Items” that can contain subclasses of the abstract “Item”.

[XmlArray("Items")]
public Item [] Items { get; set; }

Now I need to add XmlArrayItem, but the number is not “fixed”. We use so far reflection to find all subclasses with a KnownTypeProvider so it is easy to extend the assembly with new subtypes. I dont really want to hardcode all items here.

The class is defined accordingly:

[XmlRoot]
[KnownType("GetKnownTypes")]
public class Envelope {

but it does not help.

Changing Items to:

[XmlArray("Items")]
[XmlArrayItem(typeof(Item))]
public Item [] Items { get; set; }

results in:

{“The type
xxx.Adjustment
was not expected. Use the XmlInclude
or SoapInclude attribute to specify
types that are not known statically.”}

when tyrying to serialize.

Anyone an idea how I can use XmlInclude to point to a known type provider?

  • 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-21T11:03:07+00:00Added an answer on May 21, 2026 at 11:03 am

    The KnownTypesAttribute does not work for XmlSerializer. It’s only used by a DataContractSerializer. I’m quite sure that you can exchange the serializer in WCF, because I have done that for the DataContractSerializer. But if that’s not an option, you have to implement IXmlSerializable yourself and handle type lookup there.

    Before disqualifying this solution: You just have to implement IXmlSerializable just for a special class which replaces Item[]. Everything else can be handled by the default serializer.

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

Sidebar

Related Questions

Ok, lemme start out by saying Im new to this! LOL I have done
This isn't a question but I thought I'd start a thread where links to
Let me start by saying that I do not advocate this approach, but I
I'd like to: Make commonly required services visible to all classes that need them,
Okay, this question has evolved a bit, and I want to try to start
I found this via google: http://www.mvps.org/access/api/api0008.htm '******************** Code Start ************************** ' This code was
/* I start with this: */ <Report> <prop1>4</prop1> <prop2>2255</prop2> <prop3>true</prop3> <prop4>false</prop4> <prop5>true</prop5> </Report> /*
All of a sudden I start getting this error while trying to open 2
I've got in an ASP.NET application this process : Start a connection Start a
Right now we just use something like this stopWatch.Start(); try { method(); } finally

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.