代码是这样的:
public OptionsWindow()
{
if(gameOptions == null)
{
if (File.Exists("GameOptions.xml"))
{
using (var stream = File.OpenRead("GameOptions.xml"))
{
var serializer = new XmlSerializer(typeof(GameOptions));
gameOptions = serializer.Deserialize(stream) as GameOptions;
}
}
else
gameOptions = new GameOptions();
}
InitializeComponent();
}
但是运行会抛出异常:

public OptionsWindow()
{
if(gameOptions == null)
{
if (File.Exists("GameOptions.xml"))
{
using (var stream = File.OpenRead("GameOptions.xml"))
{
var serializer = new XmlSerializer(typeof(GameOptions));
gameOptions = serializer.Deserialize(stream) as GameOptions;
}
}
else
gameOptions = new GameOptions();
}
InitializeComponent();
}
但是运行会抛出异常:
