I have the following code snippet:
var familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
var doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
var doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter);
List<Element> doors = new FilteredElementCollector(doc)
.WherePasses(doorInstancesFilter)
.ToList();
FamilyInstance doorFI = (FamilyInstance)doors[0];
ElementId wallid = doorFI.Symbol.get_Parameter(BuiltInParameter.HOST_ID_PARAM)
.AsElementId();
where I try to obtain the ID of the wall containing a door. However if I run this code then the line ElementId wallid =doorFI.Symbol.get_Parameter(BuiltInParameter.HOST_ID_PARAM).AsElementId();
throws a null pointer exception. I have checked that the door in question is indeed inside a wall and should therfor have a parent object.
The test scenario I'm runing is a simple 2 rooms with 1 door between them test case.
Note that I know what a null reference expcetion is, I know doorFI.Symbol.get_Parameter(BuiltInParameter.HOST_ID_PARAM) returns null, I want to know how/why it returns null. If anything is still unclear feel free to leave a comment so I can improve this question.