开发者

Object Reference not set to an instance of object error

Can somebody help me figure out what is wrong with the code below?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜