Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.NullReferenceException on Show (11.1.0) #477

Open
Wandtket opened this issue Feb 21, 2024 · 7 comments
Open

System.NullReferenceException on Show (11.1.0) #477

Wandtket opened this issue Feb 21, 2024 · 7 comments
Assignees
Labels
Android Android only issue bug Something isn't working

Comments

@Wandtket
Copy link

Wandtket commented Feb 21, 2024

When showing a notification the notification will pop as expected but then throw a System.NullReferenceException immediately afterwards.

Steps to reproduce the behavior:

  1. Use the setup project.
  2. Pop a notification.
  3. See error

image

  • Device: Emulator
  • OS: Android 10.0 API 29
  • Version: 11.1.0
@Wandtket Wandtket added the bug Something isn't working label Feb 21, 2024
@thudugala
Copy link
Owner

@Wandtket Can you please attach a sample project?

@thudugala thudugala added the Android Android only issue label Feb 26, 2024
@Wandtket
Copy link
Author

Wandtket commented Feb 28, 2024

@thudugala I can't seem to reproduce it in a sample project which is a little frustrating,

Sorry for the delay, here's the output from the NullReferenceException:

{System.NullReferenceException: Object reference not set to an instance of an object.
   at Plugin.LocalNotification.NotificationImage.get_HasValue()
   at System.Object.HasValueGetter(Object )
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[Plugin.LocalNotification.NotificationImage, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, NotificationImage value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[Plugin.LocalNotification.NotificationImage, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].TryWrite(Utf8JsonWriter writer, NotificationImage& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[Plugin.LocalNotification.NotificationImage, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, NotificationRequest value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].TryWrite(Utf8JsonWriter writer, NotificationRequest& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Converters.ListOfTConverter`2[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].OnWriteResume(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite(Utf8JsonWriter writer, List`1 value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore(Utf8JsonWriter writer, List`1& value, JsonSerializerOptions options, WriteStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.1.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize(Utf8JsonWriter writer, List`1& rootValue, Object rootValueBoxed)
   at System.Text.Json.JsonSerializer.WriteString[List`1](List`1& value, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Serialize[List`1](List`1 value, JsonSerializerOptions options)
   at Plugin.LocalNotification.Json.NotificationSerializer.Serialize[List`1](List`1 value)
   at Plugin.LocalNotification.LocalNotificationCenter.GetRequestListSerialize(List`1 requestList)
   at Plugin.LocalNotification.Platforms.NotificationRepository.SetList(String key, List`1 list)
   at Plugin.LocalNotification.Platforms.NotificationRepository.SetDeliveredList(List`1 list)
   at Plugin.LocalNotification.Platforms.NotificationRepository.AddDeliveredRequest(NotificationRequest request)
   at Plugin.LocalNotification.Platforms.NotificationServiceImpl.ShowNow(NotificationRequest request)}

@Wandtket
Copy link
Author

@thudugala

I had thought since my original project was created on .net 6 something might've been keeping it from working properly, I created a new project starting on .net 8 and it worked fine, then I fired up the old project and for some reason it started working properly. Which is strange, I uninstalled the app from the emulator and started from scratch.

Everything appears to be working fine now, sorry for the trouble.

@peter-bozovic
Copy link

I didn't notice this error while developing or in released application that I installed, but it is reported by Android Play Console under Android Vitals !

It's:
Exception android.runtime.JavaProxyThrowable: [System.NullReferenceException]: Object reference not set to an instance of an object
at Plugin.LocalNotification.NotificationImage.get_HasValue
at System.Object.HasValueGetter

It affects any Android versions, and mostly Samsung and Xiaomi phones

From the error message, probably something happening when receiving Image attached to the notification ?

@chnoergaard
Copy link

chnoergaard commented Apr 25, 2024

I updated my project from .NET 7.0 to 8.0, and started getting these errors on version 11.1.2. Going back to version 10.1.8 fixed it but introduced other problems with permissions so I had to go back to the latest version.

At first I got the "[System.NullReferenceException]: Object reference not set to an instance of an object"-exceptions when trying to use Cancel or Clear methods when running the code in Visual Studio on an Emulator. I could'nt figure out what it was and it wasn't until CrashLytics came onboard that it mentioned this exact error so I finally could see what was the main cause.

The code works fine when running Debug or Release from Visual Studio. But when added to Google Play it crashes the app with the error:

Fatal Exception: android.runtime.JavaProxyThrowable
[System.NullReferenceException]: Object reference not set to an instance of an object
Plugin.LocalNotification.NotificationImage.get_HasValue
System.Object.HasValueGetter
System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[System.Boolean, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetMemberAndWriteJson
System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[Plugin.LocalNotification.NotificationImage, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite
System.Text.Json.Serialization.JsonConverter`1[[Plugin.LocalNotification.NotificationImage, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].TryWrite
System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1[[Plugin.LocalNotification.NotificationImage, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].GetMemberAndWriteJson
System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite
System.Text.Json.Serialization.JsonConverter`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].TryWrite
System.Text.Json.Serialization.Converters.ListOfTConverter`2[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].OnWriteResume
System.Text.Json.Serialization.JsonCollectionConverter`2[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]].OnTryWrite
System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryWrite
System.Text.Json.Serialization.JsonConverter`1[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].WriteCore
System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Collections.Generic.List`1[[Plugin.LocalNotification.NotificationRequest, Plugin.LocalNotification, Version=11.1.2.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Serialize
System.Text.Json.JsonSerializer.WriteString
System.Text.Json.JsonSerializer.Serialize
Plugin.LocalNotification.Json.NotificationSerializer.Serialize
Plugin.LocalNotification.LocalNotificationCenter.GetRequestListSerialize
Plugin.LocalNotification.Platforms.NotificationRepository.SetList
Plugin.LocalNotification.Platforms.NotificationRepository.SetDeliveredList
Plugin.LocalNotification.Platforms.NotificationRepository.RemoveByDeliveredIdList
Plugin.LocalNotification.Platforms.NotificationServiceImpl.Cancel
  • I've tried removing Plugin.Localnotification from my NuGet, closed VS, removed bin and obj folders, reopened VS and re-installed Plugin.Localnotification version 11.1.2 via NuGet again but it did'nt work.
  • I've also tried adding an Image to the NotificationRequest just to see if it could help with the Get method, but this also had no effect.
  • I've even tried using the Image.HasValue method to check if the NotificationRequest has an Image attached but even if it's value is true, the crash still occurs.

The hardest part about this is, that it seems to work fine locally but having issues after Release on Google Play, so creating a local project for testing would'nt really have any purpose.

@thudugala Can the issue be re-opened?

@thudugala thudugala reopened this Apr 26, 2024
@chnoergaard
Copy link

Okay, so I've tried a few things more without success.

I added the latest System.Text.Json to the project.
I added a DisplayAlert to check values just before the Cancel and Clear method, and the values were these:

HasValue: false
FilePath: ""
ResourceName: ""
Binary: System.Byte[]

So I can't see an issue with the data. But the error still makes the app crash exactly when the Cancel or Clear method are called.

@chnoergaard
Copy link

chnoergaard commented May 2, 2024

Well, I finally got it working but how exactly eludes me. I'll list the things I can remember I did or tried, so hopefully it can help someone else with the issue:

  • I had a .nuget folder in my project root but I had actually moved all nuget package installation to C:\n, due to some iOS LongPath issue with Windows, so I removed this folder as it was not being used and I was thinking it might cause conflicts
  • I tried setting up a custom local notification system using Microsoft.Maui.Essentials package, but uninstalled it again after I went back to trying to solve this issue
  • I noticed that the Package for 11.1.2 had multiple frameworks for net8.0. When the problem started my project was running net8.0-android34.0 but I changed this to net8.0 in my .csproj file because I was unsure if the issue had something to do with API 34.0. Today I changed it back from net8.0-android (though I had it set to net8.0, so I dunno how the -android part got added) to net8.0-android34.0 and also noticed this particular framework wants Xamarin.GooglePlayServices.Location, so I also installed this package.. I actually thought it got auto-installed since it is a dependency

Any or several of these might have helped solve the issue. Personally I think it was the latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Android only issue bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants