title: Getting exception in order by in C# Linq
body: <p>There a method called ProccesXmlResponse and there is line written below.</p>
  
  <pre><code>var myMessages = messages.OrderByDescending(x =&gt; x.MessageSentDate).ToList();
  </code></pre>
  
  <p>MessageSentDate is type of DateTime. and I am initializing the messages object for sure.although I got the below exception.Please help</p>
  
  <pre><code>Type : System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Message : Object reference not set to an instance of an object.
  Source : PHOnline.Application.Service
  Help link : 
  Data : System.Collections.ListDictionaryInternal
  TargetSite : System.DateTime &lt;ProccesXmlResponse&gt;b__6(PHOnline.Application.Model.DTO.Vitality.MyMessage)
  HResult : -2147467261
  Stack Trace :    at PHOnline.Application.Service.Implementations.Vitality.MyMessagesResponseMapper.&lt;ProccesXmlResponse&gt;b__6(MyMessage x)
     at System.Linq.EnumerableSorter`2.ComputeKeys(TElement[] elements, Int32 count)
     at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
     at System.Linq.OrderedEnumerable`1.&lt;GetEnumerator&gt;d__0.MoveNext()
     at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at PHOnline.Application.Service.Implementations.Vitality.MyMessagesResponseMapper.ProccesXmlResponse(String response)
  </code></pre>
  
  <hr>
  
  <p><strong>Model class:</strong>
      public class MyMessage
      {
          /// 
          ///     Gets or sets EntityNumber.
          /// 
          public string MessageID { get; set; }</p>
  
  <pre><code>    /// &lt;summary&gt;
      ///     Gets or sets EntityNumber.
      /// &lt;/summary&gt;
      public string MessageSubject { get; set; }
  
      /// &lt;summary&gt;
      ///     Gets or sets EntityNumber.
      /// &lt;/summary&gt;
      public DateTime MessageSentDate { get; set; }
  
      /// &lt;summary&gt;
      ///     Gets or sets EntityNumber.
      /// &lt;/summary&gt;
      public string Read { get; set; }
  
      /// &lt;summary&gt;
      ///     Gets or sets EntityNumber.
      /// &lt;/summary&gt;
      public string FileName { get; set; }
  
      /// &lt;summary&gt;
      ///     Gets or sets EntityNumber.
      /// &lt;/summary&gt;
      public string MIMEType { get; set; }
  
      /// &lt;summary&gt;
      ///     Gets or sets EntityNumber.
      /// &lt;/summary&gt;
      public string AttachmentContent { get; set; }
  }
  </code></pre>