-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
NetworkChange NetworkAddressChanged event throws NetworkInformationException on Android #77822
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionNetworkInformationException is thrown when trying to subscribe to NetworkChange.NetworkAddressChanged on Android. There is no indication in the source code that Android is UnsupportedOSPlatform but Android is not listed as supported in Microsoft Learn. Reproduction StepsAdd the following to MainActivity of a clean Android or Maui application project:
Expected behaviorConsole output when network address changes. Actual behaviorNetworkInformationException is thrown with the quite cryptic exception message "Success". Regression?This was working fine when the application ran on Mono. It also works fine on .Net6-ios and .Net6-mac. Known WorkaroundsNo response ConfigurationWhich version of .NET is the code running on? - Behavior seen on both .Net6-android with and without Maui Other informationNo response
|
Tagging subscribers to 'arch-android': @steveisok, @akoeplinger Issue DetailsDescriptionNetworkInformationException is thrown when trying to subscribe to NetworkChange.NetworkAddressChanged on Android. There is no indication in the source code that Android is UnsupportedOSPlatform but Android is not listed as supported in Microsoft Learn. Reproduction StepsAdd the following to MainActivity of a clean Android or Maui application project:
Expected behaviorConsole output when network address changes. Actual behaviorNetworkInformationException is thrown with the quite cryptic exception message "Success". Regression?This was working fine when the application ran on Mono. It also works fine on .Net6-ios and .Net6-mac. Known WorkaroundsNo response ConfigurationWhich version of .NET is the code running on? - Behavior seen on both .Net6-android with and without Maui Other informationNo response
|
(aside from the NetworkAddressChanged event issue)
If this exception is thrown from Lines 172 to 176 in 13733cd
|
@simonrozsival, please take a look. |
I can reproduce the bug locally. I'll continue investigating the issue tomorrow. |
@simonrozsival did you happen to find out whether we could support this? |
@akoeplinger I looked into it and I didn't find a good 1:1 replacement Android API. There are some ConnectivityManager APIs that seemed promissing but they don't behave the same way (for example ConnectivityManager.registerNetworkCallback). I will need to revisit this and look for some alternative ways of implementing it if it's even possible with the current Android restrictions. |
I wonder if we could start a timer/polling loop whenever someone registers the event that would continuously look for network changes |
We could do that. It would certainly work but wouldn't that be quite inefficient to do on a mobile device? |
I'm experimenting with |
With #80548 being merged we should be done here right? I don't think it makes sense to backport this to 7.0 |
I don't think we should backport the implementation. I think we can close this issue now. |
Description
NetworkInformationException is thrown when trying to subscribe to NetworkChange.NetworkAddressChanged on Android.
There is no indication in the source code that Android is UnsupportedOSPlatform but Android is not listed as supported in Microsoft Learn.
Reproduction Steps
Add the following to MainActivity of a clean Android or Maui application project:
Expected behavior
Console output when network address changes.
Actual behavior
NetworkInformationException is thrown with the quite cryptic exception message "Success".
Regression?
This was working fine when the application ran on Mono. It also works fine on .Net6-ios and .Net6-mac.
Known Workarounds
No response
Configuration
Which version of .NET is the code running on? - Behavior seen on both .Net6-android with and without Maui
What OS and version, and what distro if applicable? - Android 12/API 31
What is the architecture (x64, x86, ARM, ARM64)? - ARM
Other information
No response
The text was updated successfully, but these errors were encountered: