The Count of Barcelona was the major ruler in Catalonia from the 9th until the 17th century. The County of Barcelona was created by Charlemagne after he had conquered lands north of the river Ebro. These lands, called the Spanish March , were partitioned into various counties, of which the Count of Barcelona, usually holding other counties simultaneously, eventually obtained the primacy over the region. As the county became hereditary in one family, the bond of the counts to their Frankish overlords loosened, especially after the Capetian dynasty supplanted the Carolingians. In the 11th century the Counts formed a dynastic union with the Kingdom of Aragon, merging the two realms under a single ruler. In 1258, the king of France relinquished his feudal authority over the County in the Treaty of Corbeil. Barcelona remained part of the Crown of Aragon when the latter around 1500 entered into a union with the Kingdom of Castile, thereby forming the Spanish Kingdom. The last vestiges of the County were removed after the War of the Spanish Succession in the 18th century.