I have replicated this in my local.
Problem with the following line of code because it is not required and it is generated by Kentico as Identity filed and it is not allowed to duplicate value.
newNonce.SetValue("NonceID", nonceId);
Please remove this line and try. It should work as per your expectations.