This is not a dynamo issue, this is related to revit versions. It is because of additional revit elements being added/exposed between revit versions(eg 2018 vs 2019), therefore follow what is discussed in the following post on how to hardcode this into your script.