Object Reference not set to an instance of object error
Messages = (
from k in j.Descendants(xmlns + BLConst.MessageElement)
select new KWI.Common.CLUE.BusinessEntities.Message()
{
type = (k.Attribute(BLConst.TypeElement) != null) ? (k.Attribute(BLConst.Ty开发者_开发百科peElement).Value).ToString() : string.Empty,
MessageText = (k.Element( xmlns + BLConst.MessageElement).Value).ToString()
}
).ToList()
I get an error at select new kwi....Message(){ .. }
Thanks
Your MessageText
selection is off - k
is already a message element, yet you are trying to select a child message element from it which doesn't exist - just take the value:
MessageText = k.Value;
Either k.Attribute(...).Value
is null or k.Element(...)
is null or k.Element(...).Value
is null.
精彩评论