That sounds like a custom coding error, in the custom T4 Generator or Template.
That is just a guess.
I have found debugging template code tough and (more or less) blind.
I think there is a way to step-through-debug but I have yet to figure that out.
As such, I just make very small incremental changes to my T4 code.
Also, I catch execeptions aggressively and rethrow with added developer-friendly information.
-- Mark Kamoski