I have a webservice which I have edited, before it worked without a problem. however right now im getting this error: cannot be serialized because it does not have a parameterless constructor I have posted my class below.
public class Class
{
public class AnsweredQ
{
public string Question { get; set; }
public string Answer { get; set; }
public AnsweredQ(string _Question, string _Answer)
{
Question = _Question;
Answer = _Answer;
}
}
public class UnAnsweredQ
{
public string Question { get; set; }
public string[] Options { get; set; }
public UnAnsweredQ(string _Question, string[] _Options)
{
Question = _Question;
Options = _Options;
}
}
public class Trial
{
public string User { get; set; }
public DateTime TrialDate { get; set; }
public bool Expired { get; set; }
public Trial (string _User, DateTime _TrialDate, bool _Expired)
{
User = _User;
TrialDate = _TrialDate;
Expired = _Expired;
}
}
}
if you can solve this please explain what i did wrong :)
To be able to serialize / deserialize a class, the serializer requires a parameterless constructor. So, you need to add the parameterless constructors to your classes, i.e.:
public class AnsweredQ
{
public string Question { get; set; }
public string Answer { get; set; }
public AnsweredQ() { }
public AnsweredQ(string _Question, string _Answer)
{
Question = _Question;
Answer = _Answer;
}
}
public class UnAnsweredQ
{
public string Question { get; set; }
public string[] Options { get; set; }
public UnAnsweredQ() {}
public UnAnsweredQ(string _Question, string[] _Options)
{
Question = _Question;
Options = _Options;
}
}
public class Trial
{
public string User { get; set; }
public DateTime TrialDate { get; set; }
public bool Expired { get; set; }
public Trial ()
{
}
public Trial (string _User, DateTime _TrialDate, bool _Expired)
{
User = _User;
TrialDate = _TrialDate;
Expired = _Expired;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With