title: LINQ DataContext.SubmitChanges() in C# Reporting "Object reference not set to an instance of an object."
body: <p>I think a lot of people have had this issue but I'm not able to fix it or understand why I'm having it.  I've been tearing hair out for a couple of hours now.  </p>
  
  <p>I'm getting the error, "Object reference not set to an instance of an object." on my datacontext.SubmitChanges() on the SECOND time this method runs (I'm looping through a set of ObjectName strings):</p>
  
  <pre><code>    private Object CreateObject(string ObjectName, SystemClassEnum SystemClass)
      {
          Object result = new Object();
          result.Name = ObjectName;
          result.SystemClassID = (int)SystemClass;
          _dataContext.Objects.InsertOnSubmit(result);
          _dataContext.SubmitChanges();
          return result;
      }
  </code></pre>
  
  <p>I thought it was because the result.Name value can be null but I don't think that anymore.</p>
  
  <p>It seems like somehow the dataContext is getting closed? but in Debug Mode I check the status of the connection and it's "Open" after the error occurs.</p>
  
  <p>I'm using the repository pattern and ASP.NET MVC.</p>
  
  <p>The result object (new Object()) is an instance of a LINQ DBML auto-generated class that also has a partial class that I created with a single extension method attached.  I don't see how the extension to the class could be causing the problem.</p>
  
  <p>I'm out of ideas.</p>
  
  <p>Any thoughts?  Thanks for any help you can provide!!</p>
  
  <p>Best regards,</p>
  
  <p>Eric </p>