views:

21

answers:

1

Hey all,

I am writing a plugin dll for an application. The application loads plugin assemblies via:

assembly = Assembly.Load(System.IO.File.ReadAllBytes(filename)); 

The problem manifests itself when I attempt to serialize/deserialize a plublic class. I narrowed it down to the serialization of:

public BindingList<MyClass> MyClasses
    { get; set; }

If I comment this out, no problems. If I attempt to serialize with:

        public static void SaveSettingsFile()
        {
            try
            {
                XmlSerializer ser = new XmlSerializer(typeof(GameTimeSettings));

                TextWriter writer = new StreamWriter(SettingPath);
                ser.Serialize(writer, Settings.Instance);
                writer.Close();
            }
            catch (Exception e)
            {
                Logger.ReportException("SaveSettingsFile", e);
                Logger.ReportException("SaveSettingsFile->InnerException", e.InnerException);
            }
        }

An exception is thrown on ser.Serialize(writer, Settings.Instance) :

System.InvalidOperationException Msg=There is an error in XML document (0,, 0). ->
InnerException: Object reference not set to an instance of an object.

My class has a default, empty constructor. I have tried using sgen. In a simple testbed application I wrote, serialization works fine... it's only when the Assembly is dynamically loaded does it fault.

Furthermore, from these two threads,

http://forums.gbpvr.com/showthread.php?30384-XMLSerializer-Problems-with-Plugins , http://forums.gbpvr.com/showthread.php?32197-System.XML-Deserialization

I know I can change the type from BindingList to ArrayList and have it work; however, I would like to keep databinding working as there are quite a bit of settings to manage.

Any input would be appreciated.

A: 

John Saunders' comment appears correct for this so far, you likely are not initializing MyClasses.

Since you say it works fine with SGen, you might also want to check if it has something to do with the compile flags, like maybe try setting it to release and see if that changes things.

NickLarsen
SGen didn't work.
Chase B. Gale
Can you post more of your code then, including the initialization of GameTypeSettings as well as the constructor for MyClass?
NickLarsen