发行中的异常但不是调试

时间:2019-03-07 11:10:29

标签: c# firebase-cloud-messaging

我将C#FCM AdminSDK包装在WCF中。当我使用debug将代码发布到本地时,一切正常。使用发行版发布代码时,出现“对象引用未设置为对象实例”的信息。尝试实例化“消息”对象时。为什么会这样? 异常发生在“ var fcmMessage = new Message()”行上

using FirebaseAdmin;
using FirebaseAdmin.Messaging;
using Google.Apis.Auth.OAuth2;
using ID.Service.PushNotification.Enums;
using ID.Service.PushNotification.Models;
using ID.Service.PushNotification.ServiceHelpers;
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Hosting;

namespace ID.Service.PushNotification.Helpers
{
    public class FcmHelper
    {
        readonly static FirebaseApp app = FirebaseApp.Create(new AppOptions()
        {
            Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/jq4bb-37597f7301.json"))
        });

        public static void BulkPushNotification(List<EnrolmentModel> enrolments, string message, int messageId, DeepLink path = DeepLink.None)
        {
            foreach (EnrolmentModel enrolment in enrolments)
            {
                PushNotification(enrolment, message, messageId, path);
            }
        }

        public static async void PushNotification(EnrolmentModel enrolment, string message, int messageId, DeepLink path = DeepLink.None)
        {

            try
            {



                var pathLink = (path != DeepLink.None) ? path.GetPath() : "";

                var registrationToken = Encoding.UTF8.GetString(Convert.FromBase64String(enrolment.DeviceToken));

                LogHelper.Error("rt: " + registrationToken);
                LogHelper.Error("msg: " + message);
                LogHelper.Error("pl" + pathLink);

                var fcmMessage = new Message()
                {
                    Token = registrationToken,
                    Android = new AndroidConfig()
                    {
                        Notification = new AndroidNotification()
                        {
                            Body = message,
                            Title = "Title",
                            Sound = "bing"

                            //ClickAction = "rewards",
                            //Color = "#CA5151",
                            //Icon="",                            
                        },                        
                        Priority = Priority.Normal,
                        TimeToLive = TimeSpan.FromSeconds(2419200),

                        //Data = new Dictionary<string, string>()
                        //{
                        //    { "deepLinkPath", pathLink }
                        //},
                    }
                };

                // Send a message to the device corresponding to the provided
                // registration token.                
                string response = await FirebaseMessaging.DefaultInstance.SendAsync(fcmMessage);
                bool successfullySent = false;

                if (response.ToLower().Contains("projects/com-app/messages/0:"))
                {
                    successfullySent = true;
                }

                ResultFeedbackServiceHelper.SaveResultFeedback(
                           response,
                           Convert.ToInt32(messageId),
                           Convert.ToInt32(enrolment.DeviceId),
                           successfullySent,
                           new List<string> { enrolment.DeviceToken }
                       );
            }
            catch (Exception ex)
            {
                ResultFeedbackServiceHelper.SaveResultFeedback(
                           ex.Message,
                           Convert.ToInt32(messageId),
                           Convert.ToInt32(enrolment.DeviceId),
                           false,
                           new List<string> { enrolment.DeviceToken }
                       );

                LogHelper.Error("Error sending push messages to (fcm) gcn " + ex.ToString());
            }

        }
    }
}

异常:''2019-03-05 15:09:55,637线程:'[13]'级别:'ERROR'消息:'将推送消息发送到(fcm)gcn System.NullReferenceException错误:对象引用未设置为对象的实例。    在ID:Service.PushNotification.Helpers.FcmHelper.d__2.MoveNext()中的D:\ BuildAgents \ Agent1_work \ 475 \ s \ PNS \ Main \ ID.Service.PushNotification \ Helpers \ FCMHelper.cs:行49'

0 个答案:

没有答案
相关问题