daily pastebin goal
28%
SHARE
TWEET

Untitled

a guest Aug 15th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // ==== STORE CHARACTER ==== //
  2.  
  3.         public static void StoreCharacter(PlayerBase player)
  4.         {
  5.             using (Stream stream = File.Create(PlayerSettingsFile))
  6.             {
  7.                 XmlSerializer ser = new XmlSerializer(player.GetType());
  8.                 ser.Serialize(stream, player);
  9.             }
  10.         }
  11.  
  12.  
  13.     // ==== LOAD CHARACTER ==== //
  14.  
  15.         public static PlayerBase LoadGame()
  16.         {
  17.  
  18.             if (!File.Exists(PlayerSettingsFile))
  19.             {
  20.                return new PlayerBase("No Char Found", EntityGender.Unknown);
  21.             }
  22.  
  23.             var serializer = new XmlSerializer(typeof(PlayerBase));
  24.             using (Stream reader = File.OpenRead(PlayerSettingsFile))
  25.             {
  26.                return (PlayerBase)serializer.Deserialize(reader);
  27.             }
  28.         }
  29.  
  30. // ==== PlayerBase class === //
  31.  
  32.     [XmlInclude(typeof(Berserker))]
  33.     [XmlInclude(typeof(Shaman))]
  34.     public class PlayerBase : IEntity
  35.  
  36. // === Berserker class === //
  37.  
  38.  public class Berserker : PlayerBase
  39.  
  40.  
  41.  
  42.  
  43. // === XML FILE === //
  44.  
  45. <?xml version="1.0"?>
  46. <Berserker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  47.   <Name>Fred</Name>
  48.   <Strength>10</Strength>
  49.   <Dexterity>5</Dexterity>
  50.   <Wisdom>5</Wisdom>
  51.   <Health>25</Health>
  52.   <Gender>Male</Gender>
  53.   <CharacterClass>Berserker</CharacterClass>
  54. </Berserker>
  55.  
  56.  
  57. // === ERROR MESSAGE === //
  58.  
  59. System.InvalidOperationException
  60.   HResult=0x80131509
  61.   Message=There is an error in XML document (2, 2).
  62.   Source=System.Xml
  63.   StackTrace:
  64.    at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
  65.    at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)
  66.    at RPG.Data.FileManager.LoadGame() in C:\Projects\Role Playing Game\RPG\Data\FileManager.cs:line 55
  67.    at RPG.Frm_GameMenu.Frm_GameMenu_Load(Object sender, EventArgs e) in C:\Projects\Role Playing Game\RPG\FormGameMenu.cs:line 25
  68.    at System.Windows.Forms.Form.OnLoad(EventArgs e)
  69.    at System.Windows.Forms.Form.OnCreateControl()
  70.    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
  71.    at System.Windows.Forms.Control.CreateControl()
  72.    at System.Windows.Forms.Control.WmShowWindow(Message& m)
  73.    at System.Windows.Forms.Control.WndProc(Message& m)
  74.    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  75.    at System.Windows.Forms.Form.WmShowWindow(Message& m)
  76.    at System.Windows.Forms.Form.WndProc(Message& m)
  77.    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  78.    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  79.    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  80.  
  81. Inner Exception 1:
  82. InvalidOperationException: <Berserker xmlns=''> was not expected.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top