title: C# XML Error: System.InvalidOperationException
body: <p>I'm getting weird error when serializing this XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;SplashScreen&gt;
    &lt;Image&gt;
      &lt;Path&gt;Content/splash&lt;/Path&gt;
    &lt;/Image&gt;
  &lt;/SplashScreen&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>"A first chance exception of type 'System.InvalidOperationException'
    occurred in System.Xml.dll Additional information: Reflecting on the
    type of error occurred EasyRPG.SplashScreen. If there is a handler for
    this exception, the program may be safely continued."</p>
  </blockquote>
  
  <p>XMLManager class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Xml.Serialization;
  using System.IO;
  
  namespace EasyRPG.Managers {
  public class XmlManager&lt;T&gt; {
  
      public Type Type;
  
      public T Load (String path) {
          T instance;
          using (TextReader reader = new StreamReader(path)){
              XmlSerializer xml = new XmlSerializer(Type);
              instance = (T)xml.Deserialize(reader);
          }
          return instance;
      }
  
      public void Save (string path, object obj) {
          using (TextWriter writer = new StreamWriter(path)) {
              XmlSerializer xml = new XmlSerializer(Type);
              xml.Serialize(writer, obj);
          }
      }
  }
  }
  </code></pre>
  
  <p>I am lost, I tried everything I know(that's not much though) and still nothing.</p>
  
  <p>Image class if needed:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Xml.Serialization;
  
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Content;
  using EasyRPG;
  
  namespace TEAM_TheCity.Source {
  public class Image {
  
      public float Alpha;
      public string Path;
      public string Text, FontName;
      public Vector2 Position;
  
      public Vector2 Scale;
      public Rectangle SourceRect;
  
      public SpriteFont font;
      public GraphicsDevice GraphcsDevice;
      public Texture2D Texture;
      Vector2 origin;
  
      ContentManager content;
      RenderTarget2D renderTarget;
      public SpriteBatch SpriteBatch;
  
      public Image () {
          Path = Text = String.Empty;
          FontName = "Orbitron";
          Position = Vector2.Zero;
          Scale = Vector2.One;
          Alpha = 1.0F;
          SourceRect = Rectangle.Empty;
      }
  
      public void LoadContent(){
          content = new ContentManager(ScreenManager.Manager.Content.ServiceProvider, "Content");
  
          if(Path != String.Empty) Texture = content.Load&lt;Texture2D&gt;(Path);
  
          font = content.Load&lt;SpriteFont&gt;(FontName);
  
          Vector2 dimensions = Vector2.Zero;
  
          if(Texture != null)
              dimensions.X += Texture.Width;
          dimensions.X += font.MeasureString(Text).X;
  
          if(Texture != null)
              dimensions.Y = Math.Max(Texture.Height, font.MeasureString(Text).Y);
          else
              dimensions.Y = font.MeasureString(Text).Y;
  
          if(SourceRect == Rectangle.Empty)
              SourceRect = new Rectangle(0,0, (int)dimensions.X, (int)dimensions.Y);
  
          renderTarget = new RenderTarget2D(ScreenManager.Manager.GraphicsDevice,(int) dimensions.X, (int)dimensions.Y);
          ScreenManager.Manager.GraphicsDevice.SetRenderTarget(renderTarget);
          ScreenManager.Manager.GraphicsDevice.Clear(Color.Transparent);
          ScreenManager.Manager.SpriteBatch.Begin();
          if (Texture != null)
              ScreenManager.Manager.SpriteBatch.Draw(Texture, Vector2.Zero, Color.White);
          ScreenManager.Manager.SpriteBatch.DrawString(font, Text, Vector2.Zero, Color.White);
          ScreenManager.Manager.SpriteBatch.End();
  
          Texture = renderTarget;
  
          ScreenManager.Manager.GraphicsDevice.SetRenderTarget(null);
      }
  
      public void UnloadContent(){
  
      }
  
      public void Update(GameTime gameTime){
  
      }
  
      public void Draw(SpriteBatch SpriteBatch) {
          origin = new Vector2(SourceRect.Width / 2, SourceRect.Height /     2);
          SpriteBatch.Draw(Texture, Position + origin, SourceRect,     Color.White, 0.0f, origin, Scale, SpriteEffects.None, 0.0f);
      }
  
  }
  }
  </code></pre>
  
  <p>And SplashScreen class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  using System.Xml.Serialization;
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Content;
  using TEAM_TheCity.Source;
  
  namespace EasyRPG {
  public class SplashScreen : GameScreen{
  
      public Image Image;
  
      public SplashScreen () {
  
      }
  
      public override void LoadContent () {
          base.LoadContent();
          Image.LoadContent();
      }
  
      public override void UnloadContent () {
          base.LoadContent();
          Image.UnloadContent();
      }
  
      public override void Update (GameTime gameTime) {
          base.Update(gameTime);
          Image.Update(gameTime);
      }
  
      public override void Draw (SpriteBatch spriteBatch) {
          base.Draw(spriteBatch);
          Image.Draw(spriteBatch);
      }
  }
  }
  </code></pre>
  
  <p>GameScreen class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Xml.Serialization;
  
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Content;
  
  namespace EasyRPG {
  public class GameScreen {
  
      protected ContentManager content;
      [XmlIgnore]
      public Type Type;
  
      public GameScreen () {
          Type = this.GetType();
      }
  
      public virtual void LoadContent () {
          content = new ContentManager(ScreenManager.Manager.Content.ServiceProvider, "Content");
      }
  
      public virtual void UnloadContent () {
          content.Unload();
      }
  
      public virtual void Update (GameTime gameTime) {}
  
      public virtual void Draw (SpriteBatch spriteBatch) {}
  }
  }
  </code></pre>
  
  <p>P.S.: sorry for that much code but I am new in XML and I have no idea what is important and what is not</p>