-
Notifications
You must be signed in to change notification settings - Fork 505
Allow JNI activation of EssentialsNetworkCallback to fix #1996 #1997
Conversation
This avoids app crash with "NotSupportedException: Unable to activate instance of type Xamarin.Essentials.Connectivity+EssentialsNetworkCallback from native handle" in case callback invocation is scheduled but managed wrapper EssentialsNetworkCallback has already been disposed.
Bump - Can we get this reviewed? This issue is causing crashes in production apps... |
Could we please finish this issue? This is still causing crashes in our production |
Any news on that? |
@jfversluis I'm also gettting some crashes in AppCenter for one of my apps. Is it already fixed in MAUI Essentials? |
To anyone wtill facing this issue. We went back to using https://www.nuget.org/packages/Xam.Plugin.Connectivity and the issue went away. Really dissapointed on this issue with xamarin essentials |
I don't like this change, adding Why has it been broken? Unless you don't care, and you'll never car, adding a Enter a quick investigation: #1996 (comment) I think this is actually a multithreading issue between Java code invoking methods on
The GC can cleanup the instance "later", once Java code is no longer referencing the |
@jonpryor I also got the sporadic errors in AppCenter for some time, and I had the impression that it's only happening when the C# part of the app is long gone, but the Java part tries to receive a broadcast and had to "re-create" the C# class, since it was already GCd. At some point in time I added removing the event handler again: I got no recent errors in AppCenter anymore, although I can't say that this was the fix, as not many people use my app. |
Description of Change
This avoids app crash with "NotSupportedException: Unable to activate instance of type Xamarin.Essentials.Connectivity+EssentialsNetworkCallback from native handle" in case callback invocation is scheduled but managed wrapper EssentialsNetworkCallback has already been disposed.
This change allows JNI to create managed wrapper in case original
EssentialsNetworkCallback
is already disposed. In such a caseEssentialsNetworkCallback
is created, the callback is delivered and ignored and then the callback object disposes itself to avoid mem-leak.Bugs Fixed
API Changes
None
Behavioral Changes
None
PR Checklist
main
at time of PR