I learn that we can expand the electric potential in an infinite series of rho and cos(n*phi) when solving the Laplace equation in polar coordinates. The problem I want to consider is the expansion for the potential due to a 2D line dipole (two infinitely-long line charge separated by a small distance). In the attached image, I have written down the potential due to a line dipole (I'm pretty sure it's correct, at least the dot product and the dependence on D and r). Now I place the perfect line dipole at a position (-x0,0), and I want to calculate the potential in terms of the infinite series. The problem is that the coefficient An is different depending on whether rho is bigger than or smaller than x0 when I solve the integral using contour integral (again, pretty sure the definite integral is done correctly). At the 'imaginary' boundary of rho=x0, the potential calculated using the two different An should give the same results, but now they differ by a sign. Why is that? What have I done wrong?