Giter VIP home page Giter VIP logo

Comments (7)

alaskanrogue avatar alaskanrogue commented on June 2, 2024 1

Thanks. Regenerated.

from azure-notificationhubs-dotnet.

marstr avatar marstr commented on June 2, 2024 1

Howdy @alaskanrogue,

Try switching the line

 if (outcome.NotificationId != "")

to

if (!string.IsNullOrWhitespace(outcome.NotificationId))

Unless you're using the "Standard" SKU (e.g. most expensive SKU) of Notification Hubs, we don't return a Notifcation ID. I believe that value just happens to be null instead of the empty string, and the check above is missing it and trying to call a function that requires a notification ID.

@zhangeugenia and I were just playing around with this, and while the change above may fix this issue from above:

:"System.ArgumentNullException","message":"Value cannot be null.\r\nParameter name: notificationId"

It doesn't explain why that value is null for you in the first place. In our code, we're seeing an empty string returned, never null.

However, when we execute your code path, we can confirm that when we pass true for enableTestSend in NotificationHubClient.CreateClientFromConnectionString we get the same error you're seeing in this comment. I'll double check whether this is supposed to be supported or not.

from azure-notificationhubs-dotnet.

marstr avatar marstr commented on June 2, 2024

Howdy @alaskanrogue,

The stack trace included above doesn't give me quite enough to get started on debugging this issue. Mind providing a representative snippet of code that results in the error you're seeing?

from azure-notificationhubs-dotnet.

alaskanrogue avatar alaskanrogue commented on June 2, 2024

Howdy back, @marstr,

Below is the class implementation. It is designed to handle notifications to basically all device types. If the parameter is not enabled, UWP and iOS is delivering raw messages; Android is not, hence my enabling the parameter. I am consistently being told "Target not found". StartNotificationTask() contains the hub call.

class AsynchNotification
{
    protected int deviceType;
    protected string ownerUri;
    protected WindowsNotification winMessage;
    protected string notice;
    protected bool receivedResponse;
    public string finalSessionStatus;
    protected bool responseReceived;
    protected bool notificationAborted;
    protected DateTime startTime;
    protected int responseTimeSpan = 3;

    protected NotificationRequestHandler handler;

    public AsynchNotification(NotificationRequestHandler callHandler)
    {
        handler = callHandler;
    }

    public void StartNotificationWork(int type, string uri, WindowsNotification notificationToSend, string noticeToSend)
    {
        deviceType = type;
        ownerUri = uri;
        winMessage = notificationToSend;
        notice = noticeToSend;

        ThreadPool.QueueUserWorkItem(new WaitCallback(StartNotificationTask), null);
    }

    private async void StartNotificationTask(Object workItemState)
    {
        bool debug = false;
        bool enableTestSend = false;
        NotificationOutcome outcome;
        NotificationDetails details;

        // Set the Notification Hubs credentials for the Mobile App
        try
        {
            // Remark if not debugging
            debug = true;
            enableTestSend = true;

            // Create hub instance
            string notificationHubConnection = "Endpoint=sb://identitycheckpointnotifications.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=53Be0m1oGSuDnbyr3aGSO+nraHGPy/id/khhvnHzdWc=";
            string notificationHubName = "IdentityCheckpointNotificationsHub";

            NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(notificationHubConnection, notificationHubName, enableTestSend);

            // Send the push notification.
            try
            {
                outcome = await hub.SendDirectNotificationAsync(winMessage, ownerUri);
                if (outcome.NotificationId != "")
                {
                    details = await hub.GetNotificationOutcomeDetailsAsync(outcome.NotificationId);

                    while (details.State.Equals(2))
                    {
                        details = await hub.GetNotificationOutcomeDetailsAsync(outcome.NotificationId);
                        await Task.Delay(1000);
                    }

                    if (details.State.Equals(0) || details.State.Equals(3))
                    {
                        handler.notificationSent = true;

                        if (details.State.Equals(0))
                        {
                            handler.notificationEnqueued = true;
                        }
                    }
                    else
                    {
                        handler.notificationSent = false;

                        if (debug)
                        {
                            string uri = details.PnsErrorDetailsUri;
                        }
                    }

                    handler.notificationProcessed = true;
                }
                else
                {
                    if (outcome.State.Equals(0) || outcome.State.Equals(3))
                    {
                        handler.notificationSent = true;

                        if (outcome.State.Equals(0))
                        {
                            handler.notificationEnqueued = true;
                        }
                    }
                    else
                    {
                        handler.notificationSent = false;

                        if (debug)
                        {
                            List <Microsoft.Azure.NotificationHubs.RegistrationResult> results = outcome.Results;
                        }
                    }

                    handler.notificationProcessed = true;
                }
            }
            catch (System.Exception ex)
            {
                finalSessionStatus = "An error occurred during query execution: " + ex;
                responseReceived = false;
                notificationAborted = true;

                throw new ApplicationException("An error occurred during query execution: ", ex);
            }

            startTime = DateTime.Now;
        }
        catch (WebException ex)
        {
            if (ex.Status == WebExceptionStatus.Timeout)
            {
                receivedResponse = false;
                finalSessionStatus = "No request was able to be sent within the allocated time period.";
                responseReceived = false;
            }
            else
            {
                finalSessionStatus = "An error occurred during query execution: " + ex;
                responseReceived = false;
                notificationAborted = true;

                throw new ApplicationException("An error occurred during query execution: ", ex);
            }
        }
    }
}

from azure-notificationhubs-dotnet.

alaskanrogue avatar alaskanrogue commented on June 2, 2024

Debugging just now a different issue, but enableTestSend enabled because of having created the code snippet, I caught this exception.
Exception

from azure-notificationhubs-dotnet.

marstr avatar marstr commented on June 2, 2024

@alaskanrogue, looks like you accidentally included a SharedAccessKey in the post above. Please take a moment to generate a new primary access policy for your Notification Hub, as this one has been compromised.

This gives me what I need to start investigating though, thank you!

from azure-notificationhubs-dotnet.

marstr avatar marstr commented on June 2, 2024

I'm going to close this issue out, under the assumption that this operation truly is not supported while using enableTestSend. However, if there's any reason to believe otherwise, I'm happy to open this issue back up.

from azure-notificationhubs-dotnet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.