The Shunzhi Emperor, who died of smallpox in 1661, chose his third son Xuanye as successor because he had survived smallpox. That child reigned as the Kangxi Emperor (r. 1661–1722), who for the first time in Qing history followed the Chinese habit of primogeniture and appointed his eldest son Yinreng (1674–1725) as heir apparent. The heir apparent was removed twice because of his extravagance and abhorrent behavior, which included an attempt to assassinate the emperor. After Yinreng was demoted for good in 1712, the emperor refused to name an heir. Because Qing policy forced imperial princes to reside in the capital Beijing, many princes became involved in politics, and the Kangxi succession became particularly contested. After the Kangxi Emperor's death in 1722, his fourth son Yinzhen (1678–1735) emerged as victor and reigned as the Yongzheng Emperor, but his legitimacy was questioned for years after his accession.