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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:32:10+00:00 2026-05-31T04:32:10+00:00

We are currently developping an application using XmlSerializer from the .NET framework. Here is

  • 0

We are currently developping an application using XmlSerializer from the .NET framework.

Here is the structure of our classes:

[XmlInclude(typeof(TimeLineMediaClass))]
[XmlInclude(typeof(ImageMediaClass))]
public abstract class MediaClass
{
    public string filename { get; set; }
    public string maintitle { get; set; }
    public string subtitle { get; set; }
    public Type typeOfMedia { get; set; }
}

[XmlInclude(typeof(AudioMediaClass))]
[XmlInclude(typeof(VideoMediaClass))]
public abstract class TimeLineMediaClass : MediaClass
{
    public string title { get; set; }
    public TimeSpan length { get; set; }
    public string genre { get; set; }
}

public class AudioMediaClass : TimeLineMediaClass
{
    public string artist { get; set; }
}

public class VideoMediaClass : TimeLineMediaClass
{
    public string director { get; set; }
    public string studios { get; set; }
}

public class ImageMediaClass : MediaClass
{
    public string width { get; set; }
    public string height { get; set; }
}

Several medias of different types are added to a List, and this is what we want to serialize.

This is how the serializer is instanciated:

XmlSerializer serializer = new XmlSerializer(typeof(List<MediaClass>));

But when we launch the program and try to serialize, an exception is thrown, stating that “AudioMediaClass was not expected”.

EDIT: A few things were missing in the code I have provided. I have added some corrections in it ; more details in comments.

  • 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-31T04:32:11+00:00Added an answer on May 31, 2026 at 4:32 am

    You need to decorate your MediaClass class with

    [XmlInclude(typeof(TimeLineMediaClass))]
    

    In your example above, you have the casing wrong on TimelineMediaClass meaning the sample won’t compile for me. If you remove it, or if you do have a different class with this name, you’ll get the error you describe.

    Once you correct the casing, it should work – it does for me [noting that I also had to remove the attribute for ImageMediaClass which also doesn’t exist in your sample].

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

Sidebar

Related Questions

We are currently building the framework for developing a C# .net application using visual
I'm currently developping to application, one using the ODP.Net 9.2 and the other one
I'm currently developping an application in java using Hibernate as a persistence manager and
I am currently developing an MVC application in ASP.net. I am using AJAX.ActionLink to
The web application I'm currently developing supports CSV export from (using SELECT INTO OUTFILE)
I'm currently developing a monitoring application for some in-house hardware using net-snmp. I have
I am currently building a gallery web application using php. I am currently developping
I am currently developing an application using the Flashbuilder 4.5 framework and I am
I'm currently developing a web application using Struts2 framework. This application requires to dynamically
I am currently developing an events calendar application using ASP.NET MVC and SQL Server

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.