I have the following line of code that calls into my Entity Framework and is returning a Null Reference Exception.
List<FieldGroup> fieldGroups = dataContext.FieldGroups.Where(fieldGroup => fieldGroup.Field_Catalog_Id == fieldVersion.FieldCatalogId && fieldGroup.Field_Catalog_Version == fieldVersion.FieldCatalogVersion).ToList();
fieldVersion is being generated earlier in the method and I have confirmed that it, and its fields FieldCatalogId and FieldCatalogVersion are not null and have proper values.
My context, dataContext, while poorly named is connecting to my database and it does have rows in the FieldGroups table. I have also confirmed that a row with Field_Catalog_Id and Field_Catalog_Version matching the values being requested in the where exist so it should be able to find rows to return.
I can't determine why the line is throwing a NullReferenceException. Any ideas are appreciated. Let me know if I can provide any more useful info.
Edit: I did take a look at the locals when the exception was being thrown and nothing that was being referenced was showing up null.
I added in Debug.Assert to check that dataContext, dataContext.FieldGroups, fieldVersion, fieldVersion.FieldCatalogId, and fieldVersion.FieldCatalogVersion are not null before the problem line. The code got past all 5 of those asserts and still threw a NullReferenceException. I can't find anything within those fields that is null that could be causing the exception.