Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
Grid Exception: Object reference not set to an instance of an object
posted

I am doing a prototype with a Grid. I am reading an XML file to populate the grid. I am getting an unhandled exception that I cannot understand.

Line: 61
Error: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.NullReferenceException: Object reference not set to an instance of an object.
   at NxServer.Views.PatientDetail.client_DownloadModuleDataCompleted(Object sender, DownloadStringCompletedEventArgs e)
   at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)
   at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)    

Here is the code.

<igGrid:XamWebGrid x:Name="gridDiseaseModules" AutoGenerateColumns="True"/>

In the code behind.

void client_DownloadModuleDataCompleted(object sender, DownloadStringCompletedEventArgs e)
{
 using (TextReader XmlData = new StringReader(e.Result))
 {
  //<modules>
  //    <module>
  //        <path_id>1test</path_id>
  //        <version>2009-07-29 17:45:49</version>
  //        <path_desc>1test</path_desc>
  //        <status>N/A</status>
  //    </module>
  //</modules>
  XDocument XmlModules = XDocument.Load(XmlData);
  var Modules = from ModuleNode in XmlModules.Descendants("module")
       select new Module
       {
        PathId = ModuleNode.Element("path_id").Value,
        Version = Convert.ToDateTime(ModuleNode.Element("version").Value),
        Description = ModuleNode.Element("path_desc").Value,
        Status = ModuleNode.Element("status").Value
       };
  gridDiseaseModules.ItemsSource = Modules.ToList();
 }
}

I can iterate through the Modules collection, so I know the data is being read correctly.

It has to be something simple.