bmresearch / Solnet

Solana's .NET SDK and integration library.
https://blockmountain.io/Solnet
MIT License
319 stars 128 forks source link

[Bug] Crash with MAUI #420

Closed napangelo closed 1 year ago

napangelo commented 1 year ago

Hi,

I tried importing Solnet into my MAUI Mobile project.

This is the code:

using Solnet.Rpc;
using Solnet.Wallet;
using Solnet.Wallet.Bip39;

namespace MauiApp1;
public partial class MainPage : ContentPage
{
    int count = 0;

    public MainPage()
    {
        InitializeComponent();
    }

    private void OnTestClicked(object sender, EventArgs e)
    {
        Wallet fromWallet = new Wallet(WordCount.TwentyFour, WordList.English);

        IRpcClient rpcClient = ClientFactory.GetClient(Cluster.TestNet);
        var transactionHash = rpcClient.RequestAirdrop(fromWallet.Account.PublicKey, 100_000_000);

        Console.WriteLine($"TxHash: {transactionHash.Result}");
    }
}

On "RequestAirdrop" the Android app crashes.

This is the output:

[AutofillManager] requestHideFillUi(null): anchor = null
[OplusSystemUINavigationGestureExtImpl] regionString = null
[OplusInputMethodManagerInternal] get inputMethodManager extension: com.android.internal.view.IInputMethodManager$Stub$Proxy@2835dee
[monodroid-assembly] open_from_bundles: failed to load assembly System.Console.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Console.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly BouncyCastle.Crypto.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/BouncyCastle.Crypto.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly System.Security.Cryptography.Algorithms.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Security.Cryptography.Algorithms.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly System.Security.Cryptography.Primitives.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Security.Cryptography.Primitives.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly Chaos.NaCl.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/Chaos.NaCl.dll [External]
[Quality] stackInfo :----- pid 9778 at 2022-11-22 16:40:24.486 -----;Cmd line: com.companyname.mauiapp1;"main" prio=5 tid=2 RUNNABLE sysTid=9778;  at crc64fcf28c0e24b4cc31.ButtonHandler_ButtonClickListener.n_onClick(Native Method);  at crc64fcf28c0e24b4cc31.ButtonHandler_ButtonClickListener.onClick(ButtonHandler_ButtonClickListener.java:30);  at android.view.View.performClick(View.java:7546);  at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194);  at android.view.View.performClickInternal(View.java:7522);  at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0);  at android.view.View$PerformClick.run(View.java:29567);  at android.os.Handler.handleCallback(Handler.java:942);  at android.os.Handler.dispatchMessage(Handler.java:99);  at android.os.Looper.loopOnce(Looper.java:240);  at android.os.Looper.loop(Looper.java:351);  at android.app.ActivityThread.main(ActivityThread.java:8321);  at java.lang.reflect.Method.invoke(Native Method);  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584);  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1012);
[Quality] stackInfo :----- pid 9778 at 2022-11-22 16:40:25.998 -----;Cmd line: com.companyname.mauiapp1;"main" prio=5 tid=2 RUNNABLE sysTid=9778;  at crc64fcf28c0e24b4cc31.ButtonHandler_ButtonClickListener.n_onClick(Native Method);  at crc64fcf28c0e24b4cc31.ButtonHandler_ButtonClickListener.onClick(ButtonHandler_ButtonClickListener.java:30);  at android.view.View.performClick(View.java:7546);  at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1194);  at android.view.View.performClickInternal(View.java:7522);  at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0);  at android.view.View$PerformClick.run(View.java:29567);  at android.os.Handler.handleCallback(Handler.java:942);  at android.os.Handler.dispatchMessage(Handler.java:99);  at android.os.Looper.loopOnce(Looper.java:240);  at android.os.Looper.loop(Looper.java:351);  at android.app.ActivityThread.main(ActivityThread.java:8321);  at java.lang.reflect.Method.invoke(Native Method);  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584);  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1012);
[monodroid-assembly] open_from_bundles: failed to load assembly System.Net.Http.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Net.Http.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly System.Security.Cryptography.X509Certificates.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Security.Cryptography.X509Certificates.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly System.Diagnostics.DiagnosticSource.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Diagnostics.DiagnosticSource.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly System.Collections.NonGeneric.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Collections.NonGeneric.dll [External]
[monodroid-assembly] open_from_bundles: failed to load assembly System.Net.Requests.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.Net.Requests.dll [External]
[TrafficStats] tagSocket(102) with statsTag=0xffffffff, statsUid=-1
[monodroid-assembly] open_from_bundles: failed to load assembly System.IO.Compression.dll
Loaded assembly: /data/data/com.companyname.mauiapp1/files/.__override__/System.IO.Compression.dll [External]
[libc] Requested dump for pid 9778 (nyname.mauiapp1)

can someone help me?

Thanks Angelo

hoakbuilds commented 1 year ago

Have you tried using the async methods? RequestAirdropAsync

BifrostTitan commented 1 year ago

Yeah that's the solution. Managed to recreate the issue and that was the fix. Any time the application freezes like that and can't be closed out is a result of a thread block in the STA

`

    private async void OnTestClicked(object sender, EventArgs e)
    {
        Wallet fromWallet = new Wallet(WordCount.TwentyFour, WordList.English);
        IRpcClient rpcClient = ClientFactory.GetClient(Cluster.DevNet);
        var transactionHash = await rpcClient.RequestAirdropAsync(fromWallet.Account.PublicKey, 100_000_000);

       Debug.WriteLine($"TxHash: {transactionHash.Result}");
   }

`

napangelo commented 1 year ago

Now works! Thanks very much!