Let $A:D(A)\subset H \to H$ be a selfadjoint unbounded operator on a complex Hilbertspace $H$. Let $\lambda_0\in I$ for some open interval $I$. Define $g(\lambda):=(\lambda_0-\lambda)^{-1}(1-\chi_{I}(\lambda)) $ on $\mathbb{R}$. Then $h(\lambda):=g(\lambda)(\lambda_0-\lambda)=1-\chi_I(\lambda)$. Accoridng to spectral theorem $$h(A)=g(A)(\lambda_0-A)=Id-E(I)$$ is defined on $D(h(A))$. ($E$ is spectral measure).
Here comes my confusion. Looking at left-hand side I expect $h(A)$ to be defined at most on $D(A)$, since it's a composition of operators. But I claim $h(A)$ is defined everywhere since $$\int_\mathbb{R}|h(\lambda)|^2d \Vert E(\lambda)u \Vert^2=\int_\mathbb{R}|1-\chi_I(\lambda)|^2 d\Vert E(\lambda)u \Vert^2 \leq2^2\Vert u \Vert^2 < \infty, \quad u \in H.$$
So where is the mistake?