我正在尝试将对象存储在 Windows Phone 7.1 的独立存储设置中
班级是 -
public class container
{
public int index { get; set; }
public int left { get; set; }
public int top { get; set; }
public int[] ar { get; set; }
public int count { get; set; }
public bool mark { get; set; }
public int num_e { get; set; }
public int o { get; set; }
public bool mine { get; set; }
// some functions
}
将对象添加到隔离存储后,执行.save()语句时,会产生以下错误
“System.Runtime.Serialization.ni.dll 中发生了‘System.Runtime.Serialization.InvalidDataContractException’类型的异常,但未在用户代码中处理”
你能告诉它是如何工作的吗?
在这方面的任何帮助将不胜感激。
编辑 :: 这就是我的存储方式。
private void save_Click(object sender, RoutedEventArgs e)
{
if (save_g.Contains("n"))
{
save_g["n"] = cons.n; //cons is a class and n is a static int
}
else
save_g.Add("n", cons.n);
if (save_g.Contains("n_boxes"))
{
save_g["n_boxes"] = cons.n_boxes; //n_boxes is a static int
}
else
save_g.Add("n_boxes", cons.n_boxes);
save_g.Save();
string t = "";
container c; //class definition as above
for (int i = 0; i < cons.n; i++)
{
t = Convert.ToString(i);
c=new container(edge[i]); //edge is an object of other class
if (save_g.Contains(t))
{
save_g[t] = c;
}
else
save_g.Add(t, c);
save_g.Save(); ****Here error occurs****
}
for (int i = 0; i < cons.n_boxes; i++)
{
t = Convert.ToString(i + cons.n);
c = new container(brick[i]); //brick is an object of other class
if (save_g.Contains(t))
{
save_g[t] = c;
}
else
save_g.Add(t, c);
save_g.Save();
}
}