Hi. 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.
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):
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;
}
I thought it was because the result.Name value can be null but I don't think that anymore.
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.
I'm using the repository pattern and ASP.NET MVC.
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.
I'm out of ideas.
Any thoughts? Thanks for any help you can provide!!
Best regards,
Eric