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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:27:19+00:00 2026-06-03T08:27:19+00:00

Using WP7 & C#: I’m trying to convert my object(s) to XML so I

  • 0

Using WP7 & C#:

I’m trying to convert my object(s) to XML so I can then save that file to SkyDrive. I’ve tried following many examples without much luck. With this code I’m

 public void ConvertObjectToXmlString()
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(App.ViewModel.vehicleItemsCollection.GetType());
            System.Xml.XmlWriter xtw = System.Xml.XmlWriter.Create(ms);
            //System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(ms, System.Text.Encoding.UTF8);

            xs.Serialize(xtw, App.ViewModel.vehicleItemsCollection[0]);

            MessageBox.Show(xtw.ToString());
        }

The error is in this line: xs.Serialize(xtw, App.ViewModel.vehicleItemsCollection[0]);
I have a collection and in my test there is only 1 item. However I can imagine that when I eventually release this code that I wouldn’t have the index [0] set.

The error states:
There was an error generating the XML document

When I go further into the error message I see the following:
Cannot assign object of type OilChangeApplication.vehicle to an object of type System.Collections.ObjectModel.ObservableCollection`1[[OilChangeApplication.vehicle, OilChangeApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].

vehicleItemsCollection is a collection of vehicle… What do I need to do to get some XML so I can upload this?

  • 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-03T08:27:20+00:00Added an answer on June 3, 2026 at 8:27 am

    The error seems very explicit with a slight translation from compiler speak:
    Cannot assign object of type OilChangeApplication.vehicle to an object of type ObservableCollection<OilChangeApplication.vehicle>.

    It means your indexing of the collection cause the error, here:

    xs.Serialize(xtw, App.ViewModel.vehicleItemsCollection[0]);
    

    Because instead of passing an ObservableCollection<...> as you told the serializer above in this part: new XmlSerializer(App.ViewModel.vehicleItemsCollection.GetType());, you’re passing an instance of your model class.

    Thus you can either just remove the [0] or change the type you’re passing to the serializer and the error will disappear.

    xs.Serialize(xtw, App.ViewModel.vehicleItemsCollection);
    

    or

     var xs = new System.Xml.Serialization.XmlSerializer(OilChangeApplication.vehicle.GetType());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I'm trying do display a time line in wp7 using amCharts quickCharts . <amq:SerialChart
I am trying to create a game in using wp7 ( windows phone 7
I'm using Facebook C# SDK for my WP7 app. The authentication dialog that prompts
I'm trying to open this url using a WebBrowserTask in WP7, and it doesn't
I am currently developing application that does following: Read Inbox (using MAPI) & SMS
I'm trying to create application for WP7 using data from compass sensor. I've found
I'm using MVVM via Caliburn Micro on WP7. I have a popup that is
i'm building a wp7 application for a game using silverlight & XNA i have
I want to develop an app for WP7 using C# where a user taps

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.