[Mono-list] Code is driving me nuts!

Paul paul at all-the-johnsons.co.uk
Wed May 19 18:33:34 EDT 2010


For some reason code that I've been using for ages and in a number of
different projects is currently throwing a wobbler. (The
error is an InvalidOperationException in the XmlSerializer line).

My brain is currently in the mush phase as I'm up to my neck in
getting students through their Chemistry and Biology exams so I can't
see anything obvious - any pointers to the problem would be

The code is a proof of concept sort of thing to load in an XML file
and generate widgets and windows and the likes (including events) from
the XML file (this is the easy bit, the hard bit is the designer

I'm having to do things this way as the code I'd like to use for window
generation and subsequent import won't work with mono due to problems
with unsafe code...



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;

namespace form_from_xml
    public partial class Form1 : Form
        public Form1()

        private void loaddesign()
            FormData f;
                        f = null;
                string path_env =
Path.GetDirectoryName(Application.ExecutablePath) +
                                XmlSerializer s = new
XmlSerializer( typeof( FormData ) ); // dies
here, has problems reflecting type FormData
                                TextReader r = new
StreamReader( "designer-test.xml" );
                                f = (FormData)s.Deserialize( r );
                                MessageBox.Show("Unable to find the form
file", "File not found",

        private void Form1_Load(object sender, EventArgs e)

    public class FormData
        private ArrayList formData;

        public FormData()
            formData = new ArrayList();

        public Elements[] elements
                Elements[] elements = new Elements[formData.Count];
                return elements;
                if (value == null)
                Elements[] elements = (Elements[])value;
                foreach (Elements element in elements)

        public int AddItem(Elements element)
            return formData.Add(element);

    public class Elements
        public string name;
        public object type;
        public int xpos;
        public int ypos;
        public bool external;
        public string externalplace;
        public string text;
        public bool questions;
        public object qtype;
        public int numberqs;
        public string ansfile;
        public int backlink;
        public int forwardlink;

        public Elements()

        public Elements(string fn, object t, int x, int y, bool ext,
string extpl, string te, bool q, object qt, int num,
            string ans, int back, int end)
            name = fn;
            type = t;
            xpos = x;
            ypos = y;
            external = ext;
            externalplace = extpl;
            text = te;
            questions = q;
            qtype = qt;
            numberqs = num;
            ansfile = ans;
            backlink = back;
            forwardlink = end;
Biggles was quietly reading his favourite book when Algy burst through
the door. Distracted for a moment, Biggles surveyed what had happened
and turned a page. "Algy old man" he said, clearing his throat, "use the
handle next time..." - Taken from "Biggles combs his Hair"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20100519/aa9516fb/attachment.bin 

More information about the Mono-list mailing list