NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 37 38 39 40 41 … 93 Next »
System.XML Deserialization

 
  • 0 Vote(s) - 0 Average
System.XML Deserialization
whurlston
Offline

Posting Freak

Posts: 7,885
Threads: 102
Joined: Nov 2006
#1
2007-12-26, 08:38 AM
I'm trying to deserialize an xml file from within a plugin (C#). If I use my code in a new windows application, it works. But as soon as I place it in the plugin project, it throws an error when I attempt the deserialization. I'm hoping someone can see what I'm missing.

Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;


namespace MyApp
{
     public void GetTrailers()
     {
            XmlSerializer serializer = new XmlSerializer(typeof(TrailerList));
            FileStream fs = new FileStream(@"c:\test.xml", FileMode.Open);
            XmlReader reader = XmlReader.Create(fs);
            TrailerList trailers = new TrailerList();

            // This throws an error in the plugin.
            trailers = (TrailerList)serializer.Deserialize(reader);

            fs.Close();
    }

   [XmlRoot("records")]
    public class TrailerList
    {
        private string mDate;

        private List<cMovie> mMovies = new List<cMovie>();

        [XmlAttribute("date")]
        public string Date
        {
            get { return mDate; }
            set { mDate = value; }
        }

        [XmlElement("movieinfo")]
        public List<cMovie> Movies
        {
            get { return mMovies; }
            set { value = mMovies; }
        }

    }

    public class cMovie
    {
        private int mID;
        private string mText;

        [XmlAttribute("id")]
        public int ID
        {
            get { return mID; }
            set { mID = value; }
        }

        [XmlText]
        public string Text
        {
            get { return mText; }
            set { value = mText; }
        }
    }
}

Here is the contents of test.xml:

Code:
<?xml version="1.0" encoding="utf-8"?>
<records date="Mon, 24 Dec 2007 00:40:01 -0800">
     <movieinfo id="2460">Test 1</movieinfo>
     <movieinfo id="2461">Test 2</movieinfo>
     <movieinfo id="2462">Test 3</movieinfo>
     <movieinfo id="2463">Test 4</movieinfo>
</records>
Ommina
Offline

Senior Member

Posts: 330
Threads: 39
Joined: Feb 2006
#2
2007-12-26, 11:04 AM
Well, I can't explain why it works in a windows form and not in the plugin - but it's 3:30 and I can barely tell time.

But I did narrow it down to the use of the generic List object. Replace List<cMovie> with an Arraylist and the exception goes away.

I do remember with .NET 1.1 there were a lot more restrictions on what kinds of collections could be serialized, but I fail to see how 1.1 limitations could be affecting us here.

Reading to docs for XmlSerializer, I note this blurb:

Code:
Dynamically Generated Assemblies
To increase performance, the XML serialization infrastructure dynamically generates assemblies to serialize and deserialize specified types. The infrastructure finds and reuses those assemblies. This behavior occurs only when using the following constructors:

System.Xml.Serialization.XmlSerializer(Type)

So maybe this dynamically created assembly is interacting with the way sub finds assemblies (I AM getting three "Searching for missing assembly XmlSerializers" in the logs) and as a result... something... happens.

Or maybe not. I'm grasping.
whurlston
Offline

Posting Freak

Posts: 7,885
Threads: 102
Joined: Nov 2006
#3
2007-12-26, 03:33 PM
Ommina Wrote:Well, I can't explain why it works in a windows form and not in the plugin - but it's 3:30 and I can barely tell time.
Yup. That's how I felt as well.

Ommina Wrote:But I did narrow it down to the use of the generic List object. Replace List<cMovie> with an Arraylist and the exception goes away.
Thank you! Thank you! Thank you! Worked perfectly.

Ommina Wrote:So maybe this dynamically created assembly is interacting with the way sub finds assemblies (I AM getting three "Searching for missing assembly XmlSerializers" in the logs) and as a result... something... happens.

Or maybe not. I'm grasping.
I see those errors in the logs now that you mention it. I had not bothered to check the logs since I wasn't generating an log messages and just stepping through the debugger. That and it was 3:30 am.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't debug with app using Nutility (System.TypeInitializationException) danorum 3 2,927 2015-08-17, 10:53 PM
Last Post: danorum
  Trouble loading .NET System assemblies bgowland 3 2,385 2013-10-31, 02:37 AM
Last Post: bgowland
  Refreshing TV Guide Data (after System plugin EPG update) imilne 13 6,133 2013-03-24, 08:03 PM
Last Post: imilne
  Using Windows file system shortcuts ACTCMS 0 1,808 2010-01-26, 11:45 PM
Last Post: ACTCMS
  System.Data.DataSetExtensions mvallevand 4 9,796 2008-09-21, 06:02 AM
Last Post: mvallevand
  What SCM (Source Control Management) system do you use? JavaWiz 3 2,052 2008-08-19, 07:28 PM
Last Post: Manderson
  pluginHelper.ReturnToMainMenu(); throws System.OutOfMemoryException: Out of memory. reven 6 2,579 2006-02-21, 08:13 PM
Last Post: reven
  System.Windows.Forms.KeyEventArgs e tostring reven 1 2,563 2005-01-04, 02:45 PM
Last Post: KingArgyle

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode