title: NullReferenceException when saving to database with asp.net using EF
body: <p>I have a movie database where I'm trying to save a genre. I have the same project in winforms and there the code works, so it's probably something simple that I missed.</p>
  
  <p>Anyways, here is the code:</p>
  
  <pre><code>    MovieCollectionEntities db = new MovieCollectionEntities();
      Genre g = new Genre();
      g.GenreName = TextBoxGenresAdd.Text;
      db.Genres.Add(g);
      db.SaveChanges();
  </code></pre>
  
  <p>The error message I get is:</p>
  
  <pre><code>System.NullReferenceException was unhandled by user code
    HResult=-2147467261
    Message=Object reference not set to an instance of an object.
  </code></pre>
  
  <p>edit:<br>
  Worth mentioning is probably that I'm using master paging and the code is from the AddGenre.aspx.</p>
  
  <p>edit2: Complete answer can be found @ <a href="https://stackoverflow.com/questions/17136455/nullreferenceexception-in-dbcontext-savechanges">NullReferenceException in DbContext.saveChanges()</a></p>