private HashSet <object> TraverseReferences() { void TraverseReferencesRecursive(object reference, HashSet <object> output) { HashSet <object> references = _referenceCollector.TraverseReferences(reference); // Add the new references to the referencePool foreach (object occuringReference in references) { // Check if referencePool contains reference if it is not yet added to output if (output.Add(occuringReference)) { if (_referencePool.ContainsReference(occuringReference) == false) { // This error occurs when a SyncSource doesn't track a reference it should have tracked throw new UntrackedReferenceException(reference, occuringReference); } } } } var occuringReferences = new HashSet <object> { _rootReference }; TraverseReferencesRecursive(_rootReference, occuringReferences); return(occuringReferences); }