this question has answer here:
- what nullreferenceexception, , how fix it? 29 answers
this not don't know nullrefrenceexception
. there uncertain situation getting error.
i'm trying assign values properties of classes.
here classes.
// these classes in emailprocess namspace public class actionedemailreport { public message message { get; set; } public string savetosentitems { get; set; } } public class torecipient { public emailobject.emailaddress emailaddress { get; set; } } public class message { public string subject { get; set; } public body body { get; set; } public list<torecipient> torecipients { get; set; } } public class body { public string contenttype { get; set; } public string content { get; set; } } // below class in emailobject namespace. namespace emailobject { public class emailaddress { public string address { get; set; } } }
here code assign values properties of classes.
public void emailprocessing(string recepeint) { actionedemailreport actionedreport = new actionedemailreport(); list<torecipient>torecipient = new list<torecipient>(); emailobject.emailaddress emailaddress= new emailobject.emailaddress(); emailaddress.address = recepeint; torecipient.add(new torecipient() { emailaddress=emailaddress }); // i'm getting error on below line. actionedreport.message.torecipients = torecipient; actionedreport.message.body.content = "hello"; actionedreport.message.body.contenttype = "text"; actionedreport.savetosentitems = "true"; actionedreport.message.subject = "demo email" }
on line actionedreport.message.torecipients = torec;
getting error
system.nullreferenceexception:object reference not set instance of object.
i have checked inputs , sure assigning value torecipient
why getting error. driving me crazy.
the message
property in actionedemailreport
not being instantiated. need add constructor actionedemailreport
, new message
property. need same body
property in message
class too.
Comments
Post a Comment