I'm having trouble evaluating this integral:
$$I = \int_{-\infty}^\infty \delta (n - \|\mathbf{x}\|^2) \,\mathrm d \mathbf{x} $$
where $\delta(x)$ is Dirac delta function, $\mathbf x$ is the real $n$-dimensional vector $(x_1,\ldots,x_n)$, and $\|\mathbf{x}\|^2 = \sum_{i=1}^n x_i^2$. Here I use the short-hand notation:
$$\int_{-\infty}^\infty\mathrm d \mathbf{x} = \int_{-\infty}^\infty\mathrm d x_1 \cdots \int_{-\infty}^\infty\mathrm d x_n$$
Here is what I tried to do. Using the integral representation of Dirac's delta function $\delta (x) = \int_{- \infty}^{\infty} \frac{d \lambda}{2 \pi} e^{i \lambda x}$, I get
$$I = \int_{- \infty}^\infty d \mathbf{x} \int_{-\infty}^\infty \frac{d\lambda}{2\pi} \mathrm e^{i\lambda(n - \| \mathbf{x} \|^2)} = \int_{- \infty}^\infty \frac{d\lambda}{2\pi} e^{-i \lambda n} \left( \int_{- \infty}^\infty e^{i\lambda x^2} \, dx \right)^n$$
I evaluated the inner integral with Mathematica:
$$\int_{- \infty}^{\infty} e^{i\lambda x^2} \, dx = \sqrt{\frac{\pi}{2}} \frac{1 +i \operatorname{sgn}(\lambda)}{\sqrt{|\lambda|}}$$
But then when I try to substitute this I get a diverging integral in $\lambda$.
What did I do wrong?
Note that the original integral is well behaved. Using polar coordinates it can be shown that $I = n^{n/2-1} \pi^{n/2} / \Gamma(n/2)$ (see https://doi.org/10.1093/qmath/12.1.165, or my answer below). Some step of my derivation leads to a fictitious divergence.
Update: @user587192's answer found the error in my calculation. I cannot exchange the order of integrations on $x$ and $\lambda$. My next question is whether there is a way to rescue this calculation? Manipulations with the Fourier transform of the Dirac delta are very convenient in more complicated situations. This is evident from the algebraic complexity of the spherical coordinates appraoch. Is there way to exploit the convenience of the Fourier representation of the Dirac delta here?
There is a trick one can do to use the Fourier transform and still have converging integrals. The trick is to multiply the integrand by $\mathrm e^{(1-||\mathbf x||^2)} = 1$. Then
$$\begin{aligned} \int_{- \infty}^{\infty} \delta (1 - ||\mathbf x||^2) \mathrm d \mathbf x & = \int_{- \infty}^{\infty} \mathrm d \mathbf x \int_{- \infty}^{\infty} \frac{\mathrm d \lambda}{2 \pi} \mathrm e^{(1 +\mathfrak{i} \lambda) (1 - ||\mathbf x||^2)}\\ & = \int_{- \infty}^{\infty} \frac{\mathrm d \lambda}{2 \pi} \mathrm e^{1 +\mathfrak{i} \lambda} \left( \int_{- \infty}^{\infty} \mathrm e^{- (1 +\mathfrak{i} \lambda) x^2} \mathrm dx \right)^N\\ & = \int_{- \infty}^{\infty} \frac{\mathrm d \lambda}{2 \pi} \mathrm e^{1 +\mathfrak{i} \lambda} \left( \frac{\pi}{1 +\mathfrak{i} \lambda} \right)^{N / 2}\\ & = \pi^{N / 2} / \Gamma (N / 2) \end{aligned}$$
which is the correct result. Here all intermediate integrals converge and the integration order can be exchanged.