You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法实例化FirebaseAuthProvider接口:WPF项目Firebase认证问题求助

WPF集成Firebase认证:无法实例化FirebaseAuthProvider接口

我正在为学校项目开发WPF应用,计划集成Firebase认证功能。应用窗口可正常打开,但尝试创建测试用户时出现错误:无法实例化FirebaseAuthProvider接口。我需要创建Firebase.Auth命名空间下的FirebaseAuthProvider实例,以下是我的App.xaml.cs文件代码,希望能找到解决方案:

using Firebase.Auth;
using Firebase.Auth.Providers;
using Firebase.Auth.Repository;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Threading.Tasks;
using System.Windows;

namespace Key_Auth.wpf
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private readonly IHost host;

        public App()
        {
            // Build the host
            host = Host.CreateDefaultBuilder()
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    // Load configuration from appsettings.json
                    config.SetBasePath(Directory.GetCurrentDirectory());
                    config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
                })
                .ConfigureServices((context, services) =>
                {
                    //get firebase api from configuration
                    string firebaseApiKey = context.Configuration["FIREBASE_API_KEY"];

                    services.AddSingleton<FirebaseAuthProvider>((serviceProvider) =>
                    {
                        // Create a new FirebaseAuthProvider instance with the API key
                        //here throws me an error
                        var authProvider = new FirebaseAuthProvider(new FirebaseConfig(firebaseApiKey));

                        // Do any additional configuration here, such as setting up a user change event handler

                        return authProvider;
                    });

                    // Register services here
                    // For example:
                    // services.AddSingleton<MyService>();
                    // services.AddTransient<MyOtherService>();
                    services.AddSingleton<MainWindow>();

                    // Register MainWindow as a singleton with a callback
                    services.AddSingleton<MainWindow>((serviceProvider) =>
                    {
                        // Get any required dependencies and create the MainWindow instance
                        var mainWindow = new MainWindow();

                        // Do any additional configuration here

                        return mainWindow;
                    });
                })
                .Build();
        }

        protected override async void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Start the host
            await host.StartAsync();

            // Resolve the main window from the service provider
            var mainWindow = host.Services.GetRequiredService<MainWindow>();

            // Set the main window of the application
            MainWindow = mainWindow;

            // Show the main window
            mainWindow.Show();
        }

        protected override async void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);

            // Shutdown the host
            await host.StopAsync();
            host.Dispose();
        }
    }
}

内容的提问来源于stack exchange,提问作者Dileeka Dasanayake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 23:57:21