GetItemAtIndex inconsistent warnings

When I run a script from inside Dynamo, I don’t get any warnings. If I run the same script on the same DWG file using the Run Script command inside Civil 3D, I receive 111 warnings. All seem to be related to the GetItemAtIndex node. The results from running the script in either case are the same and correct.

Warning text:

List.GetItemAtIndex operation failed.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
The given key was not present in the dictionary.

One of the ways that I’m using the GetItemAtIndex node is to feed a function to the SortByFunction node. Could this be causing the warnings? If so, does anyone have an alternative approach?
image

Any thoughts on why I don’t get warnings when running from Dynamo, but I do get warnings when using the Run Script command in Civil 3D?