Hello Navya,
it's a strange situation to see it sometimes works and sometimes it does not.
So the client-side code seems to work...
I suggest submitting a support request ticket. Perhaps the migration had some glitches on some parts of the underlying IoT Hub infrastructure.
Provide them with the exceptions you see on the device.
The support team is capable of checking the quality of the service.
If you use a Device Provisioning Service (a recommended solution), you could migrate your devices to another IoT Hub which does not have these glitches.
If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.