Hi
error TEMPLATE_INCONSISTENT comes from the underlying PKCS#11 module from Thales HSM.
Usually it means that some of the attributes in the template aren't valid.
First of all try to remove this line
templatePub.Add(new ObjectAttribute(ObjectAttribute.CKA_VALUE_LEN, 32));
Maybe Thales HSM doesn't want this attribute.