AFAIK, the Registration Token
(registrationId) issued by GCM is used to identity the client app, and it may be the same when re-register from GCM without unregistering from GCM. Based on your code, you are using the Registrations model. Hub.UnregisterAll(registrationId)
would try to un-register the registrations with the same Registration Token (pnsHandle) from your azure notification hub.
I would recommend you capturing the exception when you call UnregisterAll
. Also, you could leverage Server Explorer from Visual Studio, choose your notification hub, then view and manage all the registrations in your hub as follows to narrow this issue:
Note: You could check with your device registrations and try to find whether you could retrieve the duplicated registrations (same PNS Identifier (Registration Token
), different tags / Azure Registration ID or different PNS Identifier (Registration Token
) for the same client app, etc.).
If you find different PNS Identifier (Registration Token
) for the same client app, I assume that your client app need to store the previous Registration Token
and compare with the latest Registration Token
, UnregisterAll the old Registration Token
if not match firstly, then register the new Registration Token
with your notification hub.
Additionally, the Installations model could avoid the duplicate registrations. For more details, you could refer to Registration management.