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

.Net MAUI app throws System.Net.NetworkInformation.NetworkInformationException when creating AblyRealtime object #1205

Closed
bikramjitkar opened this issue Feb 9, 2023 · 18 comments · Fixed by #1215
Assignees

Comments

@bikramjitkar
Copy link

Is .Net MAUI supported?

@sync-by-unito
Copy link

sync-by-unito bot commented Feb 9, 2023

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3330

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 9, 2023

@bikramjitkar I have a hunch, the error might be related to network state monitoring. ( Detailed error log will be more useful )
Can you try setting ClientOptions.AutomaticNetworkStateMonitoring to false while creating Ably instance and see if it works?

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 9, 2023

Sample code

            var options = new ClientOptions();
            options.Key = "ROOT_API_KEY_COPIED_FROM_ABLY_WEB_DASHBOARD";

            // this will disable the library trying to subscribe to network state notifications
            options.AutomaticNetworkStateMonitoring = false;
            
           // Optional - All registered listeners/callbacks will be executed on the current main thread/ UI thread instead of 
           // the background thread
            options.CaptureCurrentSynchronizationContext = true;
            options.CustomContext = SynchronizationContext.Current;

            _ably = new AblyRealtime(options);

            _ably.Connection.On(args =>
            {
                Console.WriteLine($"Connection State is {args.Current}");
            });

@bikramjitkar
Copy link
Author

Sample code

            var options = new ClientOptions();
            options.Key = "ROOT_API_KEY_COPIED_FROM_ABLY_WEB_DASHBOARD";

            // this will disable the library trying to subscribe to network state notifications
            options.AutomaticNetworkStateMonitoring = false;
            
           // Optional - All registered listeners/callbacks will be executed on the current main thread/ UI thread instead of 
           // the background thread
            options.CaptureCurrentSynchronizationContext = true;
            options.CustomContext = SynchronizationContext.Current;

            _ably = new AblyRealtime(options);

            _ably.Connection.On(args =>
            {
                Console.WriteLine($"Connection State is {args.Current}");
            });

Hi,
Thanks for replying. I tried that too but got the below exception. Any clues?

System.TypeLoadException: 'Could not load type of field 'IO.Ably.Realtime.Workflow.RealtimeWorkflow+d__36:<>u__2' (11) due to: Could not resolve type with token 010000ba from typeref (expected class 'System.Runtime.CompilerServices.ValueTaskAwaiter1' in assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e') assembly:mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e type:System.Runtime.CompilerServices.ValueTaskAwaiter1 member:(null)'

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 10, 2023

Can I get the dotnet lib version, dotnet version and platform you are trying to run the app on ( android. windows machine, ios ) ?

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 10, 2023

Also, if possible, it would be useful if you can push demo version of your app on the github and post link here so it's easy to debug the code + configuration

@bikramjitkar
Copy link
Author

Can I get the dotnet lib version, dotnet version and platform you are trying to run the app on ( android. windows machine, ios ) ?

I'm using the ably.io nuget package (1.2.10), target .net runtime - net6.0, target platform - android 12.0 - api Level 31

@bikramjitkar
Copy link
Author

here's a link to a demo app with the issue:

https://github.com/bikramjitkar/MauiAppAblyDemo

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 10, 2023

@bikramjitkar we will check and get you back on this 👍

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 13, 2023

@bikramjitkar I was able to reproduce the issue locally on the android emulator. I feel this might be related to the linker issue, where dependencies are not preserved while building .apk file. Since the MAUI framework is not matured enough, I am not able to find a proper solution for the same. (You can check the related thread through microsoft/onnxruntime#12420)

Also, Can you try running the same app on windows machine ( as a desktop app )? Let me know if it works! That should clarify the hunch

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 13, 2023

@bikramjitkar
Copy link
Author

@bikramjitkar I was able to reproduce the issue locally on the android emulator. I feel this might be related to the linker issue, where dependencies are not preserved while building .apk file. Since the MAUI framework is not matured enough, I am not able to find a proper solution for the same. (You can check the related thread through microsoft/onnxruntime#12420)

Also, Can you try running the same app on windows machine ( as a desktop app )? Let me know if it works! That should clarify the hunch

hi, yes, it does work properly when Windows Machine is selected.

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 13, 2023

@bikramjitkar try running the app in release mode for android. You can check for logs from
visual studio -> tools -> android -> device log

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 13, 2023

This seems to be related https://riptutorial.com/dot-net-core/topic/5994/understanding-system-runtime-vs--mscorlib (reason why we don't face issues in xamarin, is because it's based on mono framework (netstandard is also stable) instead of .net 6) I am not sure why dotnet build is choosing mscorlib assembly to search for System.Runtime.CompilerServices instead of using System.Runtime.CompilerServices.Unsafe assembly.

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 13, 2023

I have found similar issues related to this, involved with mscorlib, where certain types/implementation is not found.
dotnet/maui#5078
dotnet/maui#5142

For both of those issues, the app works well on windows machines, yet it fails to work on android.

I will be creating an issue for this under https://github.com/dotnet/maui/issues.

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 14, 2023

I have created a new issue for this on official repo. dotnet/runtime#82193. It seems we can't move forward without a proper explanation/fix from the MAUI team.

@sacOO7
Copy link
Collaborator

sacOO7 commented Feb 23, 2023

@bikramjitkar it seems we need to explicitly add targets for .Net 6 and .Net 7.

Meanwhile, you can use the temporary solution mentioned here
dotnet/runtime#82193 (comment)

Go into your local NuGet package cache folder /.nuget/packages/ably.io/1.2.10/lib/ and remove the mono android folder there, then rebuild the app. That will make it pick the netstandard2.0 version instead of mono android.

And it works : )

image

@sacOO7
Copy link
Collaborator

sacOO7 commented May 23, 2023

@bikramjitkar This issue has been fixed as a part of new release 1.2.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants