AFElement.LoadElementsToDepth returns a list missing a given element

Discussion created by jason.maxwell on Oct 2, 2012
Latest reply on Oct 27, 2012 by aabrodskiy

I am making use of the AFElement.LoadElementsToDepth call to return a full list of all elements in the current AF database.  I am trying to use this full list of elements to determine if a new element needs to be created during a creation process.   After getting the full list of elements I search it using the .contains(string name) method.  If the element in question is not found, create it and add it to the database.  Since the element exists but is not returned by the LoadElementsToDepth function, a new element is created and added to the root element list, but an exception is thrown that another element with the same name already exists.


This is the snippet of code that performs the list creation:

private AFDatabase currentDatabase;
private AFNamedCollection flatElementList;

private void AFGetElements()
            List templist = new List();
            foreach (AFElement element in currentDatabase.Elements)
            flatElementList = AFElement.LoadElementsToDepth(templist, false, int.MaxValue, int.MaxValue);

The issue I am having is that one of the root elements that is set as part of the search list does not end up in the returned collection.




Anyone have any thoughts on why this might happen?


an example:
the templist would have 3 elements, and the LoadElementsToDepth should have 6 total elements and flatElementList.Contains("Element3") should return true but instead it returns false. 




Some extra information:
AFSDK version:
The element in question was created previously by the same process.