Fix exceptions on DTE.ActiveDocument

Close #653.