It seems that the problem is here
directoryEntry.Properties["ServerComment"][0]
If this is the case, these extra validations should do the trick
if (directoryEntry.Properties["ServerComment"] != null &&
directoryEntry.Properties["ServerComment"].Count > 0 &&
directoryEntry.Properties["ServerComment"][0].Equals(SiteName))