désérialisation XML élément non attendu
Salut à tous,
allez je poste !
Moi aussi je veux poser des questions !!!
j'ai, dans une classe abstraite, le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| /// <summary>
/// Sérialise le personnage en XML.
/// </summary>
/// <returns>Retourne le nom qualifié complet du fichier écrit.</returns>
public string Save()
{
string fileFullName = null;
string folderPath = Properties.Settings.Default.XmlCharacterFolderPath;
DirectoryInfo dinf = new DirectoryInfo(folderPath);
if (!dinf.Exists)
dinf.Create();
if (string.IsNullOrEmpty(this.GeneralInformations.Name))
throw new SavingCharacterWithoutNameException();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
XmlSerializer xs = new XmlSerializer(this.GetType());
fileFullName = Path.Combine(folderPath, string.Concat(this.GeneralInformations.Name, ".xml"));
using (StreamWriter wr = new StreamWriter(fileFullName))
xs.Serialize(wr, this, ns);
return fileFullName;
}
/// <summary>
/// Désérialise le personnage depuis un fichier XML.
/// </summary>
/// <param name="fileFullName">Nom complet qualifié du fichier XML contenant le personnage.</param>
/// <returns>Retourne une instance de BaseAdventurer représentant le personnage.</returns>
public static BaseAdventurer Load(string fileFullName)
{
if (string.IsNullOrEmpty(fileFullName))
throw new ArgumentNullException("fileFullName");
FileInfo finf = new FileInfo(fileFullName);
if (!finf.Exists)
throw new ArgumentException("Fichier introuvable", fileFullName);
BaseAdventurer p = null;
XmlSerializer xs = new XmlSerializer(typeof(BaseAdventurer));
using (StreamReader rd = new StreamReader(fileFullName))
p = xs.Deserialize(rd) as BaseAdventurer;
return p;
} |
Le début de mon fichier XML est :
Code:
1 2 3 4
| <?xml version="1.0" encoding="utf-8" ?>
- <Assassin>
<HitPoints>13</HitPoints>
<CurrentHPs>13</CurrentHPs> |
et quand je joue la méthode Load, j'ai une exception sur la ligne en rouge:
Le message est 'il y a une erreur dans le fichier xml (2,2)... soit, je regarde l'innerException pour en savoir plus et il me dit :
<Assassin xmlns=''> n'était pas attendu
pour compléter :
ma classe abstraite
Code:
1 2
| [Serializable, XmlInclude(typeof(BattleSoul)), XmlInclude(typeof(Killer)), XmlInclude(typeof(Ranger)), XmlInclude(typeof(Knight)), XmlInclude(typeof(Elementalist)), XmlInclude(typeof(Warrior)), XmlInclude(typeof(Wizard)), XmlInclude(typeof(Priest))]
public abstract class BaseAdventurer : BaseCreature |
et
une classe en dérivant (en pasant par d'autres)
Code:
1 2
| [XmlRoot("Assassin")]
public sealed class Killer : BaseWarrior, IShadow |
j'ai beau me triturer les neurones, je ne trouve pas... je suis sûre que c('est un truc à deux balles en plus. Pour le coup, j'ai besoin d'un chien guide d'aveugle pour mettre la truffe (moi) sur l'erreur...
Merci