Dalkeith Palace is a country house in Dalkeith, Midlothian, Scotland. It was the seat of the Dukes of Buccleuch from 1642 until 1914, and is owned by the Buccleuch Living Heritage Trust. The present palace was built 1701–1711 on the site of the medieval Dalkeith Castle. The medieval castle and collegiate church Dalkeith Castle was located to the north east of Dalkeith and dated from the 12th century when it was in the possession of the Clan Graham Lords of Dalkeith. With the death of John de Graham in 1341–1342 the castle and the barony of Dalkeith passed to the Clan Douglas via his sister, Marjory, who was married to Sir William Douglas. James Douglas of Dalkeith became the Earl of Morton in the mid 15th century. The castle was strategically located in an easily defensible position above a bend in the River North Esk. Nearer the centre of Dalkeith, James Douglas, 1st Lord Dalkeith, endowed the collegiate church in 1406, where Douglas earls, lords, and knights were buried. Margaret Tudor, the bride of King James IV, stayed at Dalkeith Castle as the guest of the Earl of Morton before her formal entry to Edinburgh in 1503. In 1543, Cardinal Beaton was imprisoned in Dalkeith Castle. The castle was captured on 3 June 1548 during the war of the Rough Wooing by the English soldiers James Wilford and Thomas Wyndham, with the Spanish captain Pedro de Gamboa. Mary, Queen of Scots, rode from Edinburgh to stay a few days at Dalkeith in October 1565. From June 1574, Regent Morton, who had been captured at the siege of 1548, extended the castle. Sir John Forster, an English border warden captured at the Raid of the Redeswire, was held in the palace in July 1575. When King James VI reached his majority in October 1579, following celebrations in Edinburgh, Morton entertained the young king at Dalkeith Castle. James VI and Anne of Denmark frequently stayed at the castle. While they were in residence in August 1592, a prisoner John Wemyss of Logie escaped through their bedchamber, helped by the queen's servant, Margaret Vinstarr. In 1598 the royal master of work William Schaw prepared a nursery for the queen at Dalkeith Castle and Princess Margaret was born there on Christmas Eve. In August 1601 the infant Prince Charles was seriously ill while staying at the castle, but recovered. William, 6th Earl of Morton