The canonical commutation relation states that $$[x,p] = i \hbar\ \mathbb{I}$$ if we imagine to be in a one dimensional space.
If we take the mean value of the commutator over an eigenstate of the position $|x'\rangle$ we get $$\frac{\langle x'| [x,p] |x'\rangle}{\langle x'|x'\rangle} = \frac{\langle x'| i \hbar\ \mathbb{I} |x'\rangle}{\langle x'|x'\rangle} = i \hbar.$$
Now, instead of using the canonical commutation we write the commutator explicitly $$\frac{\langle x'| [x,p] |x'\rangle}{\langle x'|x'\rangle} = \frac{\langle x'| xp |x'\rangle}{\langle x'|x'\rangle} - \frac{\langle x'| px |x'\rangle}{\langle x'|x'\rangle}.$$
In the first term of the difference the operator $x$ acts on the bra giving the eigenvalue $x'$, while in the second term the operator $x$ acts on the ket giving again the eigenvalue $x'$, then $$\frac{\langle x'| [x,p] |x'\rangle}{\langle x'|x'\rangle} = \frac{x' \langle x'| p |x'\rangle}{\langle x'|x'\rangle} - \frac{x' \langle x'| p |x'\rangle}{\langle x'|x'\rangle} = 0.$$
I know obviously the second result it's the wrong one. Can someone point the error I'm making in the second calculation?