firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
366 stars 131 forks source link

Field not found: 'Initializer.DefaultHandleUnsuccessfulResponseFunc' issue when calling FirebaseApp.Create #284

Closed atagaew closed 3 years ago

atagaew commented 3 years ago

[READ] Step 1: Are you in the right place?

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

An application can't initialize FirebaseApp instance with error

System.MissingFieldException: Field not found: 'Initializer.DefaultHandleUnsuccessfulResponseFunc'. at FirebaseAdmin.Util.RetryOptions.get_Default() at FirebaseAdmin.Messaging.FirebaseMessagingClient.Create(FirebaseApp app) at FirebaseAdmin.Messaging.FirebaseMessaging..ctor(FirebaseApp app) at FirebaseAdmin.Messaging.FirebaseMessaging.<>c__DisplayClass5_0.b0() at FirebaseAdmin.FirebaseApp.GetOrInit[T](String id, ServiceFactory`1 initializer) at EventNotifier.FirebaseNotifier.FirebaseMessageSender.d4.MoveNext() in C:\gitlab-runner\builds\4bEsN_fP\0\fl\EventNotifier\EventNotifier\FirebaseNotifier\FirebaseMessageSender.cs:line 66

Steps to reproduce:

I have an application that sends notifications via Firebase The code that I have perfectly working on Windows 10 Home edition and on another Windows Server 2016 On the current server I have issue 'Field not found: 'Initializer.DefaultHandleUnsuccessfulResponseFunc'' when it's executing line "FirebaseApp.Create" (see the code below)

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

Relevant Code:

 public class FirebaseAppClient
    {
        private static readonly object _syncRoot = new object();
        private static FirebaseAppClient _instance;

        private FirebaseAppClient()
        {
            if (FirebaseApp.DefaultInstance == null)
            {
                FirebaseApp = FirebaseApp.Create(new AppOptions()
                {
                    Credential =
                        GoogleCredential.FromJson(
                            JsonConvert.SerializeObject(new FirebaseConfigProvider().GetConfiguration())),
                });
            }
            else
            {
                FirebaseApp = FirebaseApp.DefaultInstance;
            }
        }

        public static FirebaseAppClient GetInstance()
        {
            if (_instance == null)
            {
                lock (_syncRoot)
                {
                    _instance = new FirebaseAppClient();
                }
            }

            return _instance;
        }

        public FirebaseApp FirebaseApp { get; private set; }
    }
google-oss-bot commented 3 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

hiranya911 commented 3 years ago

Check you Google API client dependencies? The property in question comes from here: https://github.com/googleapis/google-api-dotnet-client/blob/aa4f841973671775f6e4ad9ab7a5052bcade0898/Src/Support/Google.Apis.Core/Http/BackOffHandler.cs#L60-L62

Should be available on all recent versions of the dependency. We currently have a hard dependency on Google.Apis.Auth v1.49.0, which should pull in Google.Apis.Core v1.49.0 transitively.

atagaew commented 3 years ago

Thank you. I've check the dependencies and they are looking ok, see attached file

EventNotifier.csproj.txt

This implementation is working perfectly on another server. Even if I just copy project dlls to another server it working well. What else can be the issue ?

Thank you!

hiranya911 commented 3 years ago

Difficult to tell other than it's some strange dependency binding issue at runtime. Perhaps you should try compiling some source similar to the following and see what sort of error messages you get back. Hopefully that will shed more light on the problem. Basically, force the error to occur at compile time instead of runtime.

using Google.Apis.Http;

public class Issue
{
    public static readonly Func<HttpResponseMessage, bool> TestFunc =
                BackOffHandler.Initializer.DefaultHandleUnsuccessfulResponseFunc;
}
atagaew commented 3 years ago

The issue resolved. The reason was "DLL Hell" issue of identifying right version of System.Net.Http.dll used by Google.Apis.Auth package.

The solution described here -https://stackoverflow.com/questions/65698676/asp-net-firebaseadmin-fails-to-initilize-system-missingfieldexception/65918156#65918156

hiranya911 commented 3 years ago

Might worth reporting an issue against the Google API client, and see if they can do something about that. Perhaps, they should define a specific version for the System.Net.Http dependency: https://github.com/googleapis/google-api-dotnet-client/blob/aa4f841973671775f6e4ad9ab7a5052bcade0898/Src/Support/Google.Apis.Core/Google.Apis.Core.csproj#L42-L44