Redth / PushSharp

A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), Android (C2DM and GCM - Google Cloud Message), Windows Phone, Windows 8, Amazon, Blackberry, and (soon) FirefoxOS devices!
Other
4.38k stars 1.52k forks source link

"Specified argument was out of the range of valid values" when starting broker #640

Open stu60610 opened 8 years ago

stu60610 commented 8 years ago

What version of PushSharp are you using?

PushSharp v3.0.1.0

Describe your issue:

I'm trying to send an APNS notification, it works fine in Console Program. But when I try to use it on my ASP.NET website and call the function "broker.Start();", the broker just can't start. And Got a exception like this:

"Specified argument was out of the range of valid values. Parameter name: creationOptions"

Hope someone can help, thanks.

Redth commented 8 years ago

I'm really not sure if this is entirely related to PushSharp... I don't have any methods with that parameter name, and not really sure how you would have got the exception.

You'll need to provide a full stack trace at this point.

abhamid commented 8 years ago

I also get this issue at my Production Server. Here is the stack trace.

Specified argument was out of the range of valid values. Parameter name: creationOptions

Source Error:

// Start the broker apnsBroker.Start();

Stack Trace: [ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: creationOptions] System.Threading.Tasks.Task.TaskConstructorCore(Object action, Object state, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler) +3556894 System.Threading.Tasks.Task..ctor(Object action, Object state, Task parent, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler) +88 System.Threading.Tasks.Task1..ctor(Func1 valueSelector, Task parent, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler) +110 System.Threading.Tasks.Task1.StartNew(Task parent, Func1 function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, InternalTaskOptions internalOptions, TaskScheduler scheduler, StackCrawlMark& stackMark) +86 System.Threading.Tasks.TaskFactory.StartNew(Func1 function, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler) +119 PushSharp.Core.ServiceWorker1.Start() in D:\AirFare\PushSharp-master\PushSharp-master\PushSharp.Core\ServiceBroker.cs:161 PushSharp.Core.ServiceBroker1.ChangeScale(Int32 newScaleSize) in D:\AirFare\PushSharp-master\PushSharp-master\PushSharp.Core\ServiceBroker.cs:119 PushSharp.Core.ServiceBroker1.Start() in D:\AirFare\PushSharp-master\PushSharp-master\PushSharp.Core\ServiceBroker.cs:67 SendMessage.btnSend_Click(Object sender, EventArgs e) in d:\Sites\Luchtmacht_With_Push\SendMessage.aspx.cs:70 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

CoolDixon commented 8 years ago

I had the same issue with PushSharp 4.0

After upgrading .NET from .4.0 to 4.5 the problem disappeared

nmduc073 commented 6 years ago

I have the same issue with PushSharp 4.0.

Can anyone help me, please? static void Test() { // Configuration (NOTE: .pfx can also be used here) var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "Certificates_moi.p12", "123456");

        // Create a new broker
        var apnsBroker = new ApnsServiceBroker(config);

        // Wire up events
        apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
        {

            aggregateEx.Handle(ex =>
            {

                // See what kind of exception it was to further diagnose
                if (ex is ApnsNotificationException)
                {
                    var notificationException = (ApnsNotificationException)ex;

                    // Deal with the failed notification
                    var apnsNotification = notificationException.Notification;
                    var statusCode = notificationException.ErrorStatusCode;

                    Console.WriteLine("Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");

                }
                else
                {
                    // Inner exception might hold more useful information like an ApnsConnectionException           
                    Console.WriteLine("Apple Notification Failed for some unknown reason : {ex.InnerException}");
                }

                // Mark it as handled
                return true;
            });
        };

        apnsBroker.OnNotificationSucceeded += (notification) =>
        {
            Console.WriteLine("Apple Notification Sent!");
        };

        // Start the broker
        apnsBroker.Start();

        //foreach (var deviceToken in MY_DEVICE_TOKENS) {
        //    // Queue a notification to send
        //    apnsBroker.QueueNotification (new ApnsNotification {
        //        DeviceToken = deviceToken,
        //        Payload = JObject.Parse ("{\"aps\":{\"badge\":7}}")
        //    });
        //}
        // Queue a notification to send
        apnsBroker.QueueNotification(new ApnsNotification
        {
            DeviceToken = "966661b0ee5860a70b2e095c63bbb9a3c035b6779ccfc54bf029b27f88f882ef",
            Payload = JObject.Parse("{\"aps\":{\"badge\":7}}")
        });
        // Stop the broker, wait for it to finish   
        // This isn't done after every message, but after you're
        // done with the broker
        apnsBroker.Stop();
    }