{"action":"created","issue":{"url":"https://api.github.com/repos/Redth/PushSharp/issues/629","repository_url":"https://api.github.com/repos/Redth/PushSharp","labels_url":"https://api.github.com/repos/Redth/PushSharp/issues/629/labels{/name}","comments_url":"https://api.github.com/repos/Redth/PushSharp/issues/629/comments","events_url":"https://api.github.com/repos/Redth/PushSharp/issues/629/events","html_url":"https://github.com/Redth/PushSharp/issues/629","id":137531907,"number":629,"title":"NullReferenceException when sending a GCM notification","user":{"login":"jdtaylor91","id":12166669,"avatar_url":"https://avatars.githubusercontent.com/u/12166669?v=3","gravatar_id":"","url":"https://api.github.com/users/jdtaylor91","html_url":"https://github.com/jdtaylor91","followers_url":"https://api.github.com/users/jdtaylor91/followers","following_url":"https://api.github.com/users/jdtaylor91/following{/other_user}","gists_url":"https://api.github.com/users/jdtaylor91/gists{/gist_id}","starred_url":"https://api.github.com/users/jdtaylor91/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdtaylor91/subscriptions","organizations_url":"https://api.github.com/users/jdtaylor91/orgs","repos_url":"https://api.github.com/users/jdtaylor91/repos","events_url":"https://api.github.com/users/jdtaylor91/events{/privacy}","received_events_url":"https://api.github.com/users/jdtaylor91/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-01T10:21:31Z","updated_at":"2016-03-01T22:53:05Z","closed_at":null,"body":"### What version of PushSharp are you using?\r\nPushSharp v3.0.1.0\r\n\r\n### Describe your issue:\r\nA [System.NullReferenceException] is thrown when sending a GCM notification.\r\n\r\nI 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\".\r\n\r\nPushSharp 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:\r\n``{ \"registration_ids\":[], \"to\": \"regtokenstring\" }``\r\n\r\nTo 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.\r\n\r\nLine 17 of GcmNotification.cs should be updated to first check that RegistrationIds is null.\r\n\r\nAlso 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.\r\n\r\n### What are the steps required to reproduce this issue?\r\nSend a GcmNotification with the 'To' field populated and the 'RegistrationIds' field as null.\r\n\r\n### Please provide any Exception Stack Traces\r\n`[System.NullReferenceException] Object reference not set to an instance of an object.\r\n   at PushSharp.Google.GcmNotification.ForSingleResult(GcmResponse response, Int32 resultIndex)\r\n   at PushSharp.Google.GcmServiceConnection.<processResponseOk>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at PushSharp.Google.GcmServiceConnection.<Send>d__6.MoveNext()`"},"comment":{"url":"https://api.github.com/repos/Redth/PushSharp/issues/comments/190947608","html_url":"https://github.com/Redth/PushSharp/issues/629#issuecomment-190947608","issue_url":"https://api.github.com/repos/Redth/PushSharp/issues/629","id":190947608,"user":{"login":"joeljeske","id":5332920,"avatar_url":"https://avatars.githubusercontent.com/u/5332920?v=3","gravatar_id":"","url":"https://api.github.com/users/joeljeske","html_url":"https://github.com/joeljeske","followers_url":"https://api.github.com/users/joeljeske/followers","following_url":"https://api.github.com/users/joeljeske/following{/other_user}","gists_url":"https://api.github.com/users/joeljeske/gists{/gist_id}","starred_url":"https://api.github.com/users/joeljeske/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joeljeske/subscriptions","organizations_url":"https://api.github.com/users/joeljeske/orgs","repos_url":"https://api.github.com/users/joeljeske/repos","events_url":"https://api.github.com/users/joeljeske/events{/privacy}","received_events_url":"https://api.github.com/users/joeljeske/received_events","type":"User","site_admin":false},"created_at":"2016-03-01T22:53:05Z","updated_at":"2016-03-01T22:53:05Z","body":"+1 \r\nI am also experiencing this issue. It is preventing me from sending any GCM notifications. "}}