The first version produces 0 element-matrices, and tries to assemble them. But the global matrix has no entries allocated, and thus throws an exception.
The translate to dx/ds syntax should be
Code:
a +=uhat.Trace()*vhat.Trace()*ds(definedon=mesh.Boundaries("b2"))
We want a loop over boundary elements, no need for volume elements and thus no skeleton flag.