Skip to content

Push Notification Error Invalid value at 'message.android.notification.event_time' #381

@furofo

Description

@furofo

[REQUIRED] Step 2: Describe your environment

  • Operating System version:Build 19045.3930
  • Firebase SDK version: 2.4.0
  • Firebase Product: FirebaseAdmin Nuget Package .NET 2.4.0
  • .NET version: 8.0.200
  • OS: Windows 10 Enterprise

[REQUIRED] Step 3: Describe the problem

Issues with the following error message:

FirebaseAdmin.Messaging.FirebaseMessagingException: Invalid value at 'message.android.notification.event_time' (type.googleapis.com/google.protobuf.Timestamp), Field 'event_time', Invalid time format: Failed to parse input

It occurs when trying to use Firebase SDK 2.4.0 in .NET and sending an Android notification when you have your system time set to a format that is not U.S.-based, like Europe. Currently, if your time settings are set to a region with a different time format, like Europe, it sets event_time in a format like 2024-02-26T07.00.58.787372000Z instead of 2024-02-26T07:00:58.787372000Z, which is not in the ISO 8601 standard format.

As a workaround, users can change their time settings to English, but this creates other problems. I believe I have narrowed down the issue to one line of code specifically.

In Version 2.3.0 of the SDK, a commit was made: "Closes #153. Add additional FCM options for Android Notification #203." This change, in particular, affected the FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs file. In this commit, the following code is problematic:

private string EventTimeString
{
    get
    {
        return this.EventTimestamp.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.ffffff000'Z'");
    }

    set
    {
        if (string.IsNullOrEmpty(value))
        {
            throw new ArgumentException("Invalid event timestamp. Event timestamp should be a non-empty string");
        }

        this.EventTimestamp = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.None);
    }
}

In the setter method, CultureInfo.InvariantCulture is used, which employs a standard format for parsing the DateTime but is not used in the getter, which is the source of the problem. This omission causes event_time to use the local time settings instead, leading to the incorrect format.

This is a problem because all other versions of Firebase are being deprecated in July 2023. To fix this, the getter should include CultureInfo.InvariantCulture to ensure consistent formatting:

return this.EventTimestamp.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.ffffff000'Z'", CultureInfo.InvariantCulture);

Steps to reproduce:

Steps to reproduce:
Set up Firebase in a .NET project. Make a message with an AndroidConfig object set up.
Set computer settings to use the Finnish format for the Region. (In Windows, this can be done from Clock and Region in the Control Panel.)
Set a breakpoint for the response and send the message with either FirebaseMessaging.DefaultInstance.SendEachAsync or FirebaseMessaging.DefaultInstance.SendAsync.
Inspect the response in the debugger for the failure message.

Relevant Code:

  var messages = new List<Message>()
            {
                new Message()
                {
                    Topic = EnglishNewsTopic,
                    Android = new AndroidConfig
                    {
                        Notification = new AndroidNotification
                        {
                            Title = EnglishNewsTitle,
                            Body = EnglishNewsBody,
                            ClickAction = "messages"
                        }
                    },

Response Code set Breakpoint at return result

 var result = await FirebaseMessaging.DefaultInstance.SendEachAsync(messages);
                return result;

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions