我完成了我的申请编码.但是,当我点击开始按钮时,我的应用程序引发了一个例外..:'(
A first chance exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred in System.Runtime.Serialization.dll A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll A first chance exception of type 'System.Runtime.Serialization.InvalidDataContractException' occurred in System.Runtime.Serialization.dll
所以我看到’Application_UnhandledException’的参数e,我可以知道原因.
“’Type’GPACalculator.Subject’无法序列化.请考虑使用DataContractAttribute属性对其进行标记,并使用DataMemberAttribute属性标记要序列化的所有成员.”
我只是使用默认数据类型来创建我的类.
public class Subject : INotifyPropertyChanged { private string name; private GradePoint gradePoint; private int credit; public Subject(string name) { Name = name; GradePoint = new GradePoint(); } public string Name { get { return name; } set { Debug.WriteLine("Name: " + value); if (name != value) { name = value; OnPropertyChanged("Name"); } } } public GradePoint GradePoint { get { return gradePoint; } set { if (gradePoint != value) { gradePoint = value; OnPropertyChanged("GradePoint"); } } } public int Credit { get { return credit; } set { if (credit != value) { credit = value; OnPropertyChanged("Credit"); } } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) PropertyChanged(this,new PropertyChangedEventArgs(propertyName)); } } public class GradePoint : INotifyPropertyChanged { private string mainGradePoint; private string subGradePoint; private int credit; public int Credit { get { return credit; } set { if (credit != value) { credit = value; OnPropertyChanged("Credit"); } } } public string MainGradePoint { get { return mainGradePoint; } set { value = value.ToUpper(); if (mainGradePoint != value) { mainGradePoint = value; OnPropertyChanged("MainGradePoint"); } } } public string SubGradePoint { get { return subGradePoint; } set { if (subGradePoint != value) { subGradePoint = value; OnPropertyChanged("SubGradePoint"); } } } public override string ToString() { return string.Format("{0}{1}",mainGradePoint,subGradePoint); } public double ToDouble(double perfectscore = 4.5F) { double gap = perfectscore - Math.Floor(perfectscore); double value; switch (mainGradePoint) { case "A": value = 4.0; break; case "B": value = 3.0; break; case "C": value = 2.0; break; case "D": value = 1.0; break; default: value = 0.0; return value; } switch (subGradePoint) { case "+": value += gap; break; case "-": value -= gap; break; } return value; } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) PropertyChanged(this,new PropertyChangedEventArgs(propertyName)); } }
以上是我的班级..
请帮我