I am using Visual studio 2010 with c# and SQL Management studio.
I am working on the mailbox feature.
I written a method for if a user click for reply button the content for reply is like this..
private string adjustContentForReply(List<Guid> sender)
{
string content = string.Empty;
messageID = (Guid)Session["messageID"];
//haal de ontvangers uit de database van het bericht
List<Guid> receivers = m.bussinesCollection.BussinesMessageReceiver.GetReceivers(messageID);
//pas de inhoud van het bericht aan met de details van het vorige bericht
content = "<br /><br />----------------------------------------<br />";
content += "Ontvangen op: " + m.bussinesCollection.BussinesMessageReceiver.GetMessageReceiver(messageID, boxOwner).DateReceived.ToString() + "<br />";
content += "Onderwerp: " + m.bussinesCollection.BussinesMessage.GetMessageSubject(messageID) + "<br />";
content += "Van: " + m.bussinesCollection.BussinesPerson.GetFullName(sender[0]) + "<br />";
content += "Aan: ";
//Voeg één of meerdere ontvangers toe aan details
foreach (Guid rec in receivers)
{
content += m.bussinesCollection.BussinesPerson.GetFullName(rec);
if (receivers.Count() > 1)
content += "; ";
}
content += "<br />";
content += "----------------------------------------<br /><br />";
//voeg de inhoud van het vorige bericht aan de content
content += m.bussinesCollection.BussinesMessage.GetMessageContent(messageID);
return content;
}
It is giving me error in line
content += "Ontvangen op: " + m.bussinesCollection.BussinesMessageReceiver.GetMessageReceiver(messageID, boxOwner).DateReceived.ToString() + "<br />";
the erroe is
Object reference not set to an instance of an object.
the GetMessageReceiver() is like this
public MessageReceiver GetMessageReceiver(Guid msgId, Guid personId)
{
var message = from msg in Db.MessageReceivers
where msg.MessageID.Equals(msgId) && msg.ReceiverID.Equals(personId)
select msg;
return message.Count().Equals(1) ? message.First() : null;
}
when I debugged it and taken the messageId and BoxOwnerId and fire a query in Database,it shows two rows for the given combination.
can any one help me?
Hey the problem is solved from there and now i can create a message for reply.
But on clicking on the send button page the same error now thrown there.
You get the error because you’re not checking the return value of
GetMessageReceiver(). You either need to make sure thatGetMessageReceivercannot returnnull, or you need to check the return value before using any functions on it