_hubClient.CreateOrUpdateInstallation fails silently

Menzo Steinhorst 0 Reputation points
2025-11-26T18:00:53.9+00:00

var _hubClient = NotificationHubClient.CreateClientFromConnectionString(hubConnString, hubName, true);

var testInstallation = new Installation

{

InstallationId = deviceid,

Platform = NotificationPlatform.FcmV1,

PushChannel = deviceid,

Tags = new List<string> { $"{GetDeviceTag(deviceid)}" }

// plus evt. topics uit je Subscriptions-tabel

};

try

{

_hubClient.CreateOrUpdateInstallation(testInstallation);

Console.WriteLine("CreateOrUpdateInstallationAsync: OK");

}

catch (Exception ex)

{

Console.WriteLine("CreateOrUpdateInstallationAsync: ERROR");

Console.WriteLine(ex.GetType().Name);

Console.WriteLine(ex.Message);

return;

}

var chk = await _hubClient.InstallationExistsAsync(deviceid);

var inst = _hubClient.GetInstallation(deviceid);

This never returns an installation, without throwing an error. Not after 10s, not after 2 hours....

It returns a MessagingEntityNotFoundException, 404 error.

Azure Notification Hubs
Azure Notification Hubs
An Azure service that is used to send push notifications to all major platforms from the cloud or on-premises environments.
{count} votes

1 answer

Sort by: Most helpful
  1. RAMAMURTHY MAKARAPU 1,125 Reputation points Microsoft External Staff Moderator
    2025-11-26T18:15:58.48+00:00

    Hi @Menzo Steinhorst ,

    Thanks for posting your question in the Microsoft Q&A forum.

    Reason behind you’re seeing MessagingEntityNotFoundException (404) when reading the installation from your snippet

    
    var _hubClient = NotificationHubClient.CreateClientFromConnectionString(hubConnString, hubName, true);
    
    var testInstallation = new Installation {
        InstallationId = deviceid,
        Platform = NotificationPlatform.FcmV1,
        PushChannel = deviceid,               // <-- likely not a valid FCM token
        Tags = new List<string> { $"{GetDeviceTag(deviceid)}" }
    };
    
    _hubClient.CreateOrUpdateInstallation(testInstallation); // <-- sync, non-Async overload used
    
    var chk  = await _hubClient.InstallationExistsAsync(deviceid);
    var inst = _hubClient.GetInstallation(deviceid);    // <-- sync, non-Async overload used
    
    

    Sometimes these issues happen because of how the installation APIs are being used. The .NET SDK methods for creating or updating installations are asynchronous, so you should always use the async versions like CreateOrUpdateInstallationAsync(...) and GetInstallationAsync(...) and properly await them. If you don’t, you can run into timing problems where a read happens too quickly after a write and returns a 404 even though the installation actually exists.

    Another common issue is the PushChannel value. For FCM v1, the PushChannel must be the actual Firebase registration token from the device not a device ID or any custom identifier. If the wrong value is used, the hub might accept the call, but the installation won’t behave correctly, and reads may fail. It’s also important to confirm that your hub is correctly configured with FCM v1 credentials in the Azure Portal.

    You also need to make sure the backend is using the correct connection string. Installation management requires the DefaultFullSharedAccessSignature (Listen + Send + Manage). Using a Listen-only key can cause unexpected failures or missing behavior.

    There are also some known read-after-write quirks. Even if the upsert succeeds, reading immediately afterward may return 404 due to propagation delays. A small retry with a short delay usually resolves this.

    Finally, if you delete an installation and then recreate it with the exact same data, sometimes it won’t show up again immediately. Changing even a small field like adding a temporary tag can force it to refresh correctly.

    These might be the changes can be done in your code

    
    using Microsoft.Azure.NotificationHubs;
    
    // Use the Full SAS connection string
    var hubClient = NotificationHubClient.CreateClientFromConnectionString(hubConnString, hubName /*, enableTestSend: optional */);
    
    // Build a proper installation
    var installation = new Installation
    {
        InstallationId = deviceid,                 // Your own stable ID
        Platform       = NotificationPlatform.FcmV1,
        PushChannel    = fcmRegistrationToken,     // <-- REAL FCM token from the device
        Tags           = new List<string> { GetDeviceTag(deviceid) }
    };
    
    // 1) Upsert asynchronously
    await hubClient.CreateOrUpdateInstallationAsync(installation);
    
    // 2) (Optional) small delay or retry policy before read
    await Task.Delay(300);
    
    // 3) Read asynchronously
    bool exists = await hubClient.InstallationExistsAsync(deviceid);
    if (exists)
    {
        var inst = await hubClient.GetInstallationAsync(deviceid);
        Console.WriteLine("Installation retrieved: " + inst.InstallationId);
    }
    else
    {
        Console.WriteLine("Installation not found yet; will retry."); }
    
    
    

    Did you recently delete and then re-create the same installation ID with identical tags/fields or are you using a device ID instead of the FCM registration token as PushChannel? Either of these maps directly to the 404 symptoms you described.
    Reference :

    CreateOrUpdateInstallationAsync: official .NET API docs and GetInstallationAsync & InstallationExistsAsync: official .NET API docs

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.notificationhubs.notificationhubclient.createorupdateinstallationasync?view=azure-dotnet

    Read-after-upsert 404 report from users: GitHub issue.

    https://github.com/Azure/azure-notificationhubs-dotnet/issues/345

    Kindly let us know if the above comment helps or you need further assistance on this issue.

    Please "upvote" if the information helped you. This will help us and others in the community as well.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.