title: Sending push notification with FirebaseAdmin = NullReferenceException
body: <p>I am trying to get FirebaseAdmin going in my .Net Web.Forms C# project, and I keep getting NullReferenceExceptions. I have used this link (<a href="https://stackoverflow.com/questions/38184432/fcm-firebase-cloud-messaging-push-notification-with-asp-net/54729521#54729521">FCM (Firebase Cloud Messaging) Push Notification with Asp.Net</a>) for reference (the 2019 EDIT), and that didn't work. I then move the SDK initialisation to Global.asax in the Application_Start method, and tried using the DefaultInstance to send my push (I have seen that method used as well).</p>
  
  <p>My code:</p>
  
  <p>Global.asax</p>
  
  <pre><code>  protected void Application_Start(object sender, EventArgs e)
          {
  
              // Enable firebase
              FirebaseApp.Create(new AppOptions()
              {
                  Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/xxxx-11788e8acbe2.json"))
              });
  }
  </code></pre>
  
  <p>My class that send the push:</p>
  
  <pre><code>namespace MyApp.classes
  {
      public class FCM
      {
  
          public FCM() { }
  
  
          private FirebaseAdmin.Messaging.Message CreateNotificationForTopic(string title, string notificationBody, string topic)
          {
              return new FirebaseAdmin.Messaging.Message()
              {
                  Topic = topic,
                  Notification = new Notification()
                  {
                      Body = notificationBody,
                      Title = title
                  }
              };
          }
  
  
  
          public async Task SendNotificationToTopic(string topic, string title, string body)
          {
              try
              {
                  var result = await FirebaseMessaging.DefaultInstance.SendAsync(CreateNotificationForTopic(title, body, topic));
              }
              catch (Exception x)
              {
                  string xxx = x.Message;
              }
          }
      }
  }
  </code></pre>
  
  <p>It's very hard to fix as I am just getting a NullReferenceException without any other information when I run SendNotificationToTopic. Anyone have any ideas at all? Would greatly appreciate it.</p>
  
  <p>PS: FirebaseMessage is not null:</p>
  
  <p><a href="https://i.stack.imgur.com/gUzqQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gUzqQ.png" alt="enter image description here"></a></p>
  
  <p>PS2: DefaultInstance has a value, but ProjectId is not set? Could this be it? But it exists in the Json file used when initialising the SDK?</p>
  
  <p><a href="https://i.stack.imgur.com/mMlNm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mMlNm.png" alt="enter image description here"></a></p>
  
  <p>ANSWER: Ok, so I figured it out. Many thanks to @mjwills for taking the time to help out. For some reason this thread was closed prematurely. The issue was that somehow two projects has been generated in the Service Account console, and of course, the SDK was being created facing the application that is not in use.</p>
  
  <p>I created a new Service Account under the correct project, downloaded the credentials and viola, it works.</p>