 In 617, when the general Li Yuan rebelled against the rule of Emperor Wen's son Emperor Yang, one of Li Yuan's major generals was his son Li Shimin.Fang Xuanling went to Li Shimin's camp and offered his services.It was said that as soon as Li Shimin met Fang, they became like old friends, and Li Shimin invited him to serve on staff.