Trace of a commutator is zero - but what about the commutator of $x$ and $p$? Operators can be cyclically interchanged inside a trace:
$${\rm Tr} (AB)~=~{\rm Tr} (BA).$$
This means the trace of a commutator of any two operators is zero:
$${\rm Tr} ([A,B])~=~0.$$
But what about the commutator of the position and momentum operators for a quantum particle?
On the one hand: $${\rm Tr}([x,p])~=~0,$$
while on the other hand: $$[x,p]~=~i\hbar.$$
How does this work out?
 A: $x$ and $p$ do not have finite-dimensional representations. In particular, $xp$ and $px$ are not "trace-class". Loosely, this means that the traces of $xp$ and $px$ are both infinite, although it's best to take them both to be undefined. Again loosely, if you subtract $\infty-\infty$, you can certainly get $i\hbar$. But you shouldn't. Everything works out if you think of $p$ as a complex multiple of the derivative operator, for which $\frac{\partial}{\partial x}$ and $x$ act on the infinite dimensional space of polynomials in $x$.
A: After reading Peter Morgan's answer, and giving it some more thought, I think this is actually simpler than it seems at first.
For finite-dimensional spaces the trace of a commutator is indeed always zero. For infinite-dimensional spaces the trace is not always defined, since it takes the form of an infinite sum (for countable dimension) or an integral (for continuous dimension) which do not always converge.
When the trace is defined, it obeys the same rules as in finite dimension, specifically the trace of a commutator is zero. For operators such as $x$, $p$ and their products, the trace is simply not defined, so there is no sense in asking questions about it.
When computing thermal averages, the factor $e^{-\beta H}$ makes sure the trace converges, since the energy is always bound from below (otherwise the system is unphysical).
I'm sure the concepts mentioned by @Peter Morgan are important in this context (boundedness, KMS-condition), but I don't know anything about them, and I think the answer I just provided suffices for practical purposes.
A: Fleshing out @Peter Morgan's answer a bit, to the effect that $x$ and $p$ are not bounded operators, so their commutator need not be bounded. First 
 note that 
$$[x^n,p] = i\hbar nx^{n-1}  ~,$$
hence the operator norms of both sides satisfy 
 $$ 2\| p\| ~ \|x\|^n \geq \|x^np \| + \|px^n \| \geq n \hbar \|x\|^{n-1}$$
 so that,  for any $n$, 
$$2\|x\|~\|p\|\geq n \hbar~. $$
Since $n$  can be arbitrarily large,  at least one l.h.s. operator cannot be bounded, and the dimension of the underlying Hilbert space cannot be finite. Utilizing the (bounded) Weyl relations,  it can actually be shown that both operators are unbounded.

Now for the magic of the paradox resolving itself: 
In finite (N-dimensional) Hilbert space representations of $x$ and $p$ (Weyl's QM around a circle), the commutator does indeed vanish, as it should, but the right hand side is not quite the identity, but a finite matrix with 0s in the diagonal, so, then traceless, all right. Santhanam, T. S.; Tekumalla, A. R. (1976). "Quantum mechanics in finite dimensions". Foundations of Physics 6 (5) p. 583.   doi:10.1007/BF00715110. 
In this remarkably insightful paper, it is shown that, in the continuum limit, N⟶ ∞, this very matrix goes to the Dirac-δ, the infinite-dimensional identity under discussion here! Cf. Q10,11 of an Exam I've given in the past.
A: I think that the problem stems from the action of the operator $\hat p$. Please correct me if I am mistaken. 
The action of the operator $\hat p$ in the quantum space is defined as 
$<x|\hat p|a>=-i \hbar \partial_x <x|a>$
if the state $|a>$ does not depend on x. In fact, if the state $|a>$ depended on $x$, like for instance $|a>=f(x)|b>$ for any scalar function $f(x)$, then clearly the equation
$<x|\hat p|a>=<x|\hat p f(x)|b>=-i \hbar \partial_x <x|f(x)|b>= -i \hbar \partial_x (f(x) <x|b>) $
would be badly defined, as it could be evaluated in another different way:
$<x|\hat p|a>=<x|\hat p f(x)|b>=f(x) <x|\hat p |b>=f(x)(-i \hbar) \partial_x <x|b>$
The second evaluation comes from the fact that, in Standard Quantum Mechanics, it is postulated that any operator acts on ket vectors and not on scalars (with the exception the Time reversal operator, which is not of any use here).
The commutator relation $\left[\hat x, \hat p\right]=i\hbar$ is obtained from the action of the operator $\hat p$ as defined above. Thus, it comes straightforwardly that such a commutation relation cannot be generally used in a scalar product ($<x|...|ket>$) if the ket state on the right depends on $x$.
Having said that, when you perform the trace of the commutator $\left[\hat x, \hat p\right]$, you are doing
$Tr\Big[\left[\hat x, \hat p\right]\Big]=\int dx <x|(\hat x\hat p-\hat p\hat x)|x>=\int dx <x|(x\hat p-\hat p x)|x>$,
where in the last step above I have just extracted the eigenvalues from the eigenstates $|x>$.
In the above equation you have a scalar product where the ket on the right depends on $x$. Thus, you'll have to be careful in the evaluation and you cannot use the $xp$-commutation relations straight away. With a little care, everyone can see from the above equation that, indeed, the trace gives zero 
$\int dx <x|(x\hat p-\hat p x)|x>=\int dx \,x<x|(\hat p-\hat p )|x>=0$,
as it should.
Whereas, if you had used the $xp$-commutation relations from the outset, you would have wrongly found 
$Tr\Big[\left[\hat x, \hat p\right]\Big]=Tr\Big[i\hbar\Big]=i\hbar$.
Edited after Joe's Comment 
In the last equation I forgot the dimensionality of the space. It must be modified as
$Tr\Big[\left[\hat x, \hat p\right]\Big]=Tr\Big[i\hbar\Big]=i\hbar\,D$ 
where $D$ are the dimensions of the quantum space you are taking the trace in. Thanks Joe.
A: 2.1c) Suppose that $A,B,I$ are $n \times n$ matrices, where $n$ is a finite positive integer. Then
if:
$$AB − BA = iqI$$
we have:
$$\mathrm{Tr}(AB − BA) = 0$$
but:
$$\mathrm{Tr}(iqI) = iqn$$
which is a contradiction.
