最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - Getting the default firebaseapp already exists in .NET Core while sending notifications - Stack Overflow

matteradmin8PV0评论

We have implemented the notifications and it works fine when we do the regular testing. However, when concurrent users uses the same API then we get below error.

The default firebaseapp already exists. However, by checking the solution on the internet, we have implemented the below solution in the class constructor

if (FirebaseApp.DefaultInstance == null)
{
    FirebaseApp.Create(new AppOptions()
    {
        Credential = GoogleCredential.FromJson(JsonConvert.SerializeObject(<Passing Firebase Config here>))
    });
}

Then sending the notification using this code:

string result = await FirebaseMessaging.DefaultInstance.SendAsync(message);

Still we are getting the error as default FirebaseApp already exists.

Any help on this is appreciated!

We have implemented the notifications and it works fine when we do the regular testing. However, when concurrent users uses the same API then we get below error.

The default firebaseapp already exists. However, by checking the solution on the internet, we have implemented the below solution in the class constructor

if (FirebaseApp.DefaultInstance == null)
{
    FirebaseApp.Create(new AppOptions()
    {
        Credential = GoogleCredential.FromJson(JsonConvert.SerializeObject(<Passing Firebase Config here>))
    });
}

Then sending the notification using this code:

string result = await FirebaseMessaging.DefaultInstance.SendAsync(message);

Still we are getting the error as default FirebaseApp already exists.

Any help on this is appreciated!

Share Improve this question edited Nov 18, 2024 at 14:11 marc_s 757k184 gold badges1.4k silver badges1.5k bronze badges asked Nov 18, 2024 at 14:03 XamDevXamDev 3,67713 gold badges63 silver badges104 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
import firebase_admin
from firebase_admin import credentials, firestore

class FirebaseManager:
    def __init__(self):
        if not firebase_admin._apps:
            cred = credentials.Certificate('path/to/your/serviceAccountKey.json')
            firebase_admin.initialize_app(cred, {
                'databaseURL': 'https://your-database-url.firebaseio'
            })
        self.db = firestore.client()

# Usage

firebase_manager = FirebaseManager()
Post a comment

comment list (0)

  1. No comments so far