Hello Ahmed,
Thanks for the response.
The snippet shared seems to be correct. The error 9 returning on first attempt suggest invalid handle was passed.
Hence, please check the handle's value passed in read function at the first attempt using debugging mode.
Kindly be suggested to contact our support team at https://supportportal.gemalto.com/csm as it might be helpful to have a closer investigation.
Best regards,
Parth