While young, he attended first the college of nobles in Milan and later studied in Como and then moved to Venice and finally to Siena. Having embarked on his diplomatic career, in 1802 he obtained his first official post at the Napoleonic Italian Republic as assistant secretary to the Consulta of State. His career came to an abrupt end, however, in 1804 when he decided to volunteer in the Grande Armée in Italy in the artillery branch, receiving public praise from the president, Francesco Melzi d'Eril, for being the first nobleman to join. For this purpose, he initially took preparatory courses in the military schools of La Fère and Strasbourg before becoming a lieutenant. From 1805 until 1809, he took part in the War of the Fifth Coalition against the Austrian Empire, in particular in the Battle of Ulm, the Battle of Austerlitz, the Battle of Raab, and in Battle of Wagram, after which he obtained a promotion to captain and the Legion of Honour on the field.