 He gained experience in the practice of canon law.He held major offices in the Roman Curia from a relatively early age.During the French occupation of Rome at the end of the 18th century, he took refuge in Vienna, where he became allied with the Habsburg monarchy.