I have a function $$f(x)=e^{\cos{(x)}}\cos{(\sin{(x)})}$$ that I want to integrate from $0$ to $2\pi$.
Using Mathematica, the indefinite integral evaluates out to be $$\frac{-i\operatorname{Ei}(e^{ix})+i\operatorname{Ei}(e^{-ix})}{2}+C$$ where $\operatorname{Ei}(x)$ is the exponential integral.
When I ask Mathematica the definite integral directly, it gives a $2\pi$, but when I try to use the fundamental theorem of calculus, $$\implies\left.\frac{-i\operatorname{Ei}(e^{ix})+i\operatorname{Ei}(e^{-ix})}{2}\right|^{2\pi}_0=\frac{-i\operatorname{Ei}(e^{2\pi\cdot i})+i\operatorname{Ei}(e^{2\pi\cdot -i})}{2}-\frac{-i\operatorname{Ei}(e^{0i})+i\operatorname{Ei}(e^{-0i})}{2}$$ $$\implies\frac{-i\operatorname{Ei}(1)+i\operatorname{Ei}(1)}{2}-\frac{-i\operatorname{Ei}(1)+i\operatorname{Ei}(1)}{2}=0$$
Why do I get an incorrect value of 0 when I try to use the fundamental theorem of calculus on this integral?

$$I= \int_{0}^{2\pi} e^{\cos x}\cos{(\sin x)} dx $$
From the Euler's formula:
$$I= \int_{0}^{2\pi} e^{\cos x}\left[\frac{e^{i\sin x}+e^{-i \sin x}}{2}\right] dx = \frac{1}{2} \int_{0}^{2\pi} \left[e^{\cos x + i \sin x} + e^{\cos x - i \sin x}\right] dx = \frac{1}{2} \int_{0}^{2\pi} \left[e^{\cos x + i \sin x} + e^{\cos(-x) + i \sin (-x)}\right] dx = \frac{1}{2} \int_{0}^{2\pi} \left[e^{e^{ix}} + e^{e^{-ix}}\right] dx $$
If we do the change of variable (see Appendix)
$$e^{ix} = z$$ $$dx = \frac{dz}{zi}$$
$$I= \frac{1}{2} \int_{0}^{2\pi} \left[e^{e^{ix}} + e^{e^{-ix}}\right] dx = \frac{1}{2i}\oint_{|z|=1} \frac{e^{z}+e^{\frac{1}{z}}}{z} dz = \underbrace{\frac{1}{2i}\oint_{|z|=1} \frac{e^{z}}{z} dz}_{A} +\underbrace{\frac{1}{2i}\oint_{|z|=1}\frac{e^{\frac{1}{z}}}{z} dz}_{B} $$
Now, apply the Cauchy's integral formula for A : $$f(a)=\frac{1}{2\pi\mathrm{i}}\oint_C \frac{f(z)}{z-a}\mathrm{d}z$$
with $f(z) = e^{z}$, $a= 0$ and $C$ the unit circle:
$$A = \frac{1}{2i}\oint_{|z|=1} \frac{e^{z}}{z} dz = \pi $$
For $B$, use the residue theorem
Expand $\displaystyle \frac{e^{\frac{1}{z}}}{z}$:
$$\frac{e^{\frac{1}{z}}}{z} = \frac{1}{z}+\frac{1}{z^2}+\frac{1}{z^32!}+\frac{1}{z^43!}+...$$
Therefore $\displaystyle \operatorname{Res}\left(\frac{e^{\frac{1}{z}}}{z} ,0\right) = 1$
Then
$$B = \frac{1}{2i}\oint_{|z|=1}\frac{e^{\frac{1}{z}}}{z} dz = \pi \operatorname{Res}\left(\frac{e^{\frac{1}{z}}}{z} ,0\right) = \pi $$ \
Hence
$$\boxed{ I = \int_{0}^{2\pi} e^{\cos x}\cos{(\sin x)} dx = 2\pi }$$
Appendix
This method will be useful in evaluating definite integrals of the type
$$\int_{0}^{2\pi} F(e^{i\theta})d\theta$$
The fact that $\theta$ varies from $0$ to $2\pi$ suggest that we consider $\theta$ as an argument of a point $z$ on the unit circle $C = \left\{ z \Big| |z|=1\right\}$ centered at the origin; hence we write $z =e^{i\theta} \quad 0 \leq \theta \leq 2\pi$. When we make this substitution using the equations:
$$ e^{i\theta} = z$$ $$d\theta = \frac{dz}{zi}$$
The integral becomes the contour integral
$$\int_{0}^{2\pi} F(e^{i\theta})d\theta = \oint_{|z|=1} F(z)\frac{dz}{zi}$$
Conversely, if we have the complex function:
$$f(z) = \frac{F(z)}{zi}$$
and the contour $\gamma(\theta) = e^{i\theta} \quad 0\leq \theta\leq 2\pi$. By definiton, the contour integral in $\gamma(\theta)$ is:
$$\oint_{\gamma} f(z) dz = \int_{0}^{2\pi} f(\gamma(\theta))\gamma'(\theta) d\theta = \int_{0}^{2\pi} \frac{F(e^{i\theta})}{e^{i\theta}i} ie^{i\theta} d\theta = \int_{0}^{2\pi} F(e^{i\theta}) d\theta $$
So, whenever you find an integral of the type $\int_{0}^{2\pi} F(e^{i\theta}) d\theta$ try to evaluate it converting it in a contour integral and then applying the techniques of complex integration.