6

I enable all exceptions, and get this weird exception:

First-chance exception at 0x773ac41f in MyApp.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x0038c23c..

the issue in "System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(T));"

public T GetObjectFromFile(string fileFullPath)
{
    if (System.IO.File.Exists(fileFullPath) == false)
    {
        return default(T);
    }
    System.IO.StreamReader file = new System.IO.StreamReader(fileFullPath);

    try
    {
        System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(T));
        return (T)reader.Deserialize(file);
    }
    catch
    {
        return default(T);
    }
    finally
    {
        file.Close();
    }
}
CSDev
  • 3,177
  • 6
  • 19
  • 37
Joseph
  • 1,716
  • 3
  • 24
  • 42
  • 3
    It is entirely normal, the reference answer [is here](http://stackoverflow.com/a/3798614/17034). – Hans Passant Oct 15 '13 at 17:05
  • 1
    This is not normal, this is sad! If you are using XmlSerializers than debugging should be painful? – watbywbarif Sep 09 '15 at 11:59
  • Does this answer your question? [FileNotFoundException in ApplicationSettingsBase](https://stackoverflow.com/questions/3494886/filenotfoundexception-in-applicationsettingsbase) – StayOnTarget Jul 20 '21 at 14:16

0 Answers0