public static Category ToCategory(this BuiltInCategory bic, UIDocument uidoc) { foreach (Category category in uidoc.Document.Settings.Categories) { Category val = category; if (val.Id.GetHashCode() == bic.GetHashCode()) { return(val); } } Category result = null; try { result = uidoc.Document.Settings.Categories .get_Item(bic); return(result); } catch (Exception) { return(result); } }