B dorian might have the same notes as A major but it's not harmonically the same -- e.g. a B dorian line will probably be trying to resolve to the B tonic, which can create a tension (playing "outside", in jazz terms), although not as much as playing a line with notes from outside the scale.
The exact point at which it switches from "playing a line in A major" to "playing a line in B dorian" is fuzzy, there's hundreds of years of theoretical analysis dedicated to unpicking that sort of thing.