开发者

Object Reference not set to an instance of object error

开发者 https://www.devze.com 2023-03-03 17:21 出处:网络
Can somebody help me figure out what is wrong with the code below? Messages = ( from k in j.Descendants(xmlns + BLConst.MessageElement)

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

精彩评论

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