New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NullReferenceException when sending a GCM notification #629
Comments
+1 |
joeljeske - there is a work around for this. Instead of populating the 'To' field, just populate 'RegistrationIds', this avoids the HTTP 400 response and also avoids the NullReferenceException. So something like: instead of: |
I committed some code that should help with this. Basically, it will look and see if you specified To, and if there are no registraton id's specified, and if so, when serializing, it will exclude the Could someone please try this out from master and confirm it fixes their issue? |
Fix for NullReferenceException issue - Redth#629 Additional fix for retrieving oldRegistrationId from the 'To' field if 'RegistrationIds' is empty or null
There was still an issue resulting in the NullReferenceException, it should be fixed in my pull request above. Your commit has removed the HTTP 400 response from GCM though - thanks. |
Closing this as the previous request was merged. Thanks for everyone's help and input! |
Fix for NullReferenceException issue - #629 Additional fix for retrieving oldRegistrationId from the 'To' field if 'RegistrationIds' is empty or null
What version of PushSharp are you using?
PushSharp v3.0.1.0
Describe your issue:
A [System.NullReferenceException] is thrown when sending a GCM notification.
I am in the process of upgrading from PushSharp v2 to PushSharp v3 and I have been having quite a few issues with the GCM notifications. The issues stemmed from trying to use the 'To' property of the GcmNotification.cs class, populating this results in a HTTP 400 response from GCM, due to the following reason - "Must use either "registration_ids" field or "to", not both".
PushSharp v3 does not currently validate this and if a GcmNotification is created using the constructor AND the 'To' property is populated it will result in a HTTP 400 response as the following JSON is submitted:
{ "registration_ids":[], "to": "regtokenstring" }
To work around this i manually set RegistrationIds to NULL, this then resulted in the below NullReferenceException as the GcmNotification is expecting RegistrationIds to be populated.
Line 17 of GcmNotification.cs should be updated to first check that RegistrationIds is null.
Also if possible it would be nice to have any error messages from GCM passed through the PushSharp library, currently any HTTP 400 response results in a GcmConnectionException being thrown, which ends up with any meaningful error message from GCM being lost.
What are the steps required to reproduce this issue?
Send a GcmNotification with the 'To' field populated and the 'RegistrationIds' field as null.
Please provide any Exception Stack Traces
[System.NullReferenceException] Object reference not set to an instance of an object. at PushSharp.Google.GcmNotification.ForSingleResult(GcmResponse response, Int32 resultIndex) at PushSharp.Google.GcmServiceConnection.<processResponseOk>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at PushSharp.Google.GcmServiceConnection.<Send>d__6.MoveNext()
The text was updated successfully, but these errors were encountered: