nodes = data.Descendants(XName.Get("{http://schemas.microsoft.com/LiveSearch/2008/04/XML/web}Results")).Nodes();
System.Collections.Generic.IEnumerable<Result> res = new List<Result>();
if (nodes.Count() > 0)
{
var results = from uris in nodes
select new Result
{
URL =
((XElement)uris).Element(XName.Get("{http://schemas.microsoft.com/LiveSearch/2008/04/XML/web}Url")).Value,
Title =
((XElement)uris).Element(XName.Get("{http://schemas.microsoft.com/LiveSearch/2008/04/XML/web}Title")).Value,
Description =
((XElement)uris).Element(XName.Get("{http://schemas.microsoft.com/LiveSearch/2008/04/XML/web}Description")).Value,
DateTime =
((XElement)uris).Element(XName.Get("{http://schemas.microsoft.com/LiveSearch/2008/04/XML/web}DateTime")).Value,
};
res = results;
}
, 제목, 설명 및 날짜 시간 변수 정의.
이 모든 것이 정상적으로 작동하지만 노드의 '노드'에 설명 요소가 포함되어 있지 않은 경우 (또는 적어도 이것이 무엇을 던지는 것 같아도) 프로그램은 "res = results;" 코드 줄로 '개체 참조가 설정되지 않음 ...'오류가 발생하고 '새 결과 선택'바로 뒤에 전체 섹션이 강조 표시됩니다.
어떻게 수정합니까?
문제가 지속됩니다. 노드에서 누락 된 요소가 아닐 수도 있습니다. '세이프 가드'를 추가하기 위해이 글을 다르게 쓸 수있는 방법이 있습니까? – Ryan
@ 라이언 : 대안 코드를 사용해보십시오. 여전히 실패하는 경우, 잠시이지만 완전한 * 프로그램 (XML 포함)을 질문에 편집하여 진행 상황을 볼 수 있습니다. –
코드를 작성하는이 더 좋은 방법은 문제를 피했습니다 .. Jon – Ryan