Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

XML Serialization crashing on some computers

$
0
0

@ImFromEurope wrote:

So my Save / Load system uses XML.
It has been working without problems so far, but now one of my testers has crash when trying to load game or starting a new game. Error seems to be in XML Serialization for some reason...

Here's my XML Handler

namespace MyGame
{
    public class SaveHandler
    {
        public static void SaveData(object IClass, string filename)
        {
            StreamWriter writer = null;
            try
            {
                XmlSerializer xmlSerializer = new XmlSerializer((IClass.GetType()));
                writer = new StreamWriter(filename);
                xmlSerializer.Serialize(writer, IClass);
            }
            finally
            {
                if (writer != null)
                    writer.Close();
                writer = null;
            }
    }
}

public class LoadHandler<T>
{
    public static Type type;
    
    public LoadHandler()
    {
        type = typeof(T);
    }
    
    public T LoadData(string filename)
    {
        if (!System.IO.File.Exists(filename))
            { return default(T); }

        T result;
        XmlSerializer xmlserializer = new XmlSerializer(type);
        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
        
        try
        { result = (T)xmlserializer.Deserialize(fs); }
        catch
        { return default(T); }
        
        fs.Close();
        return result;
    }
}
}

The error says

Unhandled Exception: System.InvalidOperationException: 
There was an error reflecting type 'MyGame.SavedGame'. ---> System.InvalidOperationException: 
There was an error reflection field 'PlayerPos'. ---> System.InvalidOperationException: 
There was an error reflecting type 'Microsoft.Xna.Framework.Vector2'. ---> System.IO.FileLoadException: 
Could not load file or assemply 'System.Runtime.Serialization, Version=4.0.0.0, 
Culture=neutral, PiublicKeyToken=dsf2q34sdaf231' or one of its dependencies.
 Not enough storage is available to process this command. (Exception from HRESULT: 0x800700008)
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, 0projectHandleOnStackType)

pic of crash

Please help :frowning:

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles