Of course I solve it a few moments after I post it.
For anyone who might stumble across this, the line which reads:
if (TileBounds.IsValid != 0) { continue; }
Just needs to be adjusted to:
if (TileBounds.IsValid == 0) { continue; }
I was trying to get polygons from invalid tiles.