You're a level 17+ Wizard and you cast True Polymorph on yourself to turn yourself into a CR 17 Adult Gold Dragon. This grants you the stat block of said Adult Gold Dragon, including its Change Shape ability, allowing it to assume the form of "a humanoid or beast with a Challenge Rating no higher than its own". It uses this ability to turn into a CR 12 Archmage, which has the Spellcasting feature, allowing it to cast spells using as an 18th level spellcaster, using its intelligence score.

Once they expend a number of spell slots from its new form, it proceeds to use its new 9th-level spell slot to cast True Polymorph on itself again, turning into a brand new Adult Gold Dragon form, and then using Change Shape to turn into a brand new Archmage form, and then repeats this process to gain an infinite number of spell slots.

**Is there anything that prevents this from working?** 

I know that True Polymorph is a Concentration spell, so the first True Polymorph would end when they cast the second one, I don't think they lose the spell they're Concentrating on if they lose the Spellcasting feature that gave them the slot in the first place? 5e doesn't have any hidden rules, and there doesn't seem to be anything about it working that way in the Spellcasting chapter of the PHB - and if it did work that way, wouldn't it break Polymorph spells in general, since they lose their Spellcasting class feature while Polymorphed?

Obviously the chain gets broken if they fail a Concentration saving throw, but they'd get the Adult Gold Dragon's Legendary Resistance to help them out, there - and it'd get reset every time they True Polymorph themselves, too.