I was interested in the analytical calculation of the following sum: $$ \sum\limits_{j=1}^{N-1} \dfrac{ \exp \left( i \pi kj/N \right) }{\sin \left( \pi j / N \right)},$$ where $N$ is an arbitrary positive integer, and $0 \le k \le N$.
As an inspiration I took answers by @metamorphy from here, and in a similar fashion was able to find that: $$ \sum\limits_{j = 0}^{N-1} \dfrac{\exp \left( i 2 \pi k j / N \right) }{1 + i 2 z \sin \left( 2 \pi j / N \right) - z^2} = \dfrac{ N (-z)^{-k} \left( (-z)^N - (-z)^{k+N} z^k + (-z^2)^k - (-z^2)^N \right) }{\left( 1 + z^2 \right) \left( 1 - (-z)^N \right) \left( 1 - z^N \right)}, $$ where $0 \le k \le N$, and $z$ is not a singularity. Obviously, this preliminary answer is useful, as we now only need to carefully take the limit $\lim\limits_{z\to1} \ldots$, and set $N \to 2 N$.
From the sum above we can subtract the term with $j=0$ (as it is the source of divergence for $z=1$), and obtain:
$$\sum\limits_{j = 1}^{N-1} \dfrac{\exp \left( i 2 \pi k j / N \right) }{i 2 \sin \left( 2 \pi j / N \right)} = \lim\limits_{z \to 1} \left[ \left( \sum\limits_{j = 0}^{N-1} \frac{\exp \left( i 2 \pi k j / N \right) }{1 + i 2 z \sin \left( 2 \pi j / N \right) - z^2} \right) - \dfrac{1}{1-z^2} \right] = \dfrac{1}{4} \left( -2k + N - \dfrac{2 N}{(-1)^k + (-1)^{1+k-N}} \right).$$
And this answer works perfectly for odd $N$, while for even $N$ it is divergent. It is clear as for even $N$ not only the term with $j=0$ is divergent, but also the term $j=N/2$, so, a naive strategy would be to subtract this second source of divergency, which is $\dfrac{\exp \left( i \pi k\right)}{1-z^2}$, but this clearly does not work, as the Eq. above suggests that this won't help with that denominator $(-1)^k + (-1)^{1+k-N}$.
Basically, it means that I have to separately find the sum $\sum\limits_{j = 1}^{N-1} \dfrac{\exp \left( i 2 \pi k j / N \right) }{i 2 \sin \left( 2 \pi j / N \right)}$ with a condition $N = 2 \tilde{N}$, which is exactly the sum that was intended to be found! (which is a bit funny, hehe, as the problem is reduced to itself for even N).
What am I doing wrong, and may there be an alternative approach? I have an intuition that the problem is due to two different divergences, one of which appears for continuous $z$, and the other for discrete $N$, and may be it requires a more delicate treatment.
UPDATE: Basically, I was able to obtain that:
$$ \lim\limits_{z \to 1} \left[ \sum\limits_{j=0}^{N-1} \dfrac{\exp(i 2 \pi k j / N)}{1 + i 2 z \sin(2 \pi j / N) - z^2} - \text{div. terms} \right] = \begin{cases} \frac{1}{2} \left( N - 2 k \right), & \text{ if $N$ is even, and $k$ is odd,}\\ 0, & \text{ if $N$ is even, and $k$ is even,} \\ \frac{1}{4} \left( - 2 k + N + (-1)^{k+1} N \right), & \text{ if $N$ is odd.} \end{cases}$$
As for even $N, k$ the answer is $0$, then the trick $N \to 2 N$ is useless, as it will not give any information about the original sum, right? Probably, Need to use some other trick to cover this case.