title: MVC5 / C# - Cannot perform runtime binding on a null reference
body: <p>I'm trying to figure out what's causing a <code>Cannot perform runtime binding on a null reference</code> error from this code:</p>
  
  <pre><code>var query = "SELECT Id, UserName, List_Order, LoggedIn " + 
              "FROM AspNetUsers" +
              "WHERE LoggedIn = 1" + 
              "ORDER BY List_Order ASC";
  
  var conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
  var cmd = new SqlCommand(query, conn);   
  conn.Open();
  var rdr = cmd.ExecuteReader();
  var n = 0;
  while(rdr.Read())
  {
      if (Convert.ToString(rdr["UserName"]) != null)
      {
          ViewBag.speakers[n] = new string[4] {
              Convert.ToString(rdr["Id"]),
              Convert.ToString(rdr["UserName"]),
              Convert.ToString(rdr["List_Order"]),
              Convert.ToString(rdr["LoggedIn"]) 
          };
  
          //Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot 
          //perform runtime binding on a null reference
          n++;
      }
  }
  </code></pre>
  
  <p>The <code>n++</code> increment seems to be the cause of this error and I don't understand why.</p>
  
  <p>Updated code to reflect possible solutions. However, the error still remains.</p>
  
  <p>Tried this with the same result:</p>
  
  <pre><code>if (!string.IsNullOrWhiteSpace(Convert.ToString(rdr["UserName"]))) {
          List&lt;string&gt; speakers = new List&lt;string&gt;();
          speakers.Add(Convert.ToString(rdr["Id"]));
          speakers.Add(Convert.ToString(rdr["UserName"]));
          speakers.Add(Convert.ToString(rdr["List_Order"]));
          speakers.Add(Convert.ToString(rdr["LoggedIn"]));
  
          ViewBag.speakers[n] = speakers;
          n++;
  }
  </code></pre>