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

[Bug]: GetAsync in WebAPI.cs doesn't return response correctly in MAUI environment #1119

Open
alexp9982 opened this issue Aug 15, 2022 · 2 comments
Labels

Comments

@alexp9982
Copy link

What did you expect to happen?

I test my code on a Console App before putting code in my MAUI application, and the code works perfectly there.

Instead of that, what actually happened?

However, when I put the nearly exact same code in my MAUI application found here, the application becomes indefinitely frozen. I traced this back to the GetAsync method in the WebAPI.cs file. The method calls GetAsyncInternal, which returns a response object. The return statement gets called, but for some reason, in the MAUI application, after the return statement runs, this is where the application starts hanging.

Please see additional information

Which operating system are you running on?

Windows

Which .NET Runtime are you running on?

.NET Framework

Version

6

Relevant log output

No response

Example Code

try
        {
            KeyValue ownedGames;
            if (user1a.Length == 17 && user1a.All(char.IsDigit))
            {
                using (dynamic playerService = WebAPI.GetInterface("IPlayerService", apikeya))
                {
                    ownedGames = playerService.GetOwnedGames(steamid: Convert.ToUInt64(user1a),
                        include_appinfo: true, include_played_free_games: true);
                }
                var gameCount = ownedGames[ "game_count" ].AsString();
                if (string.IsNullOrWhiteSpace(gameCount))
                {
                    StatusText = "";
                    InvalidText = "User 1 is not valid or has no games, ensure User 1 is correct and try again";
                    ButtonEnabled = true;
                    return;
                }
            }

            else
            {
                string user1AsString;
                using (dynamic steamUser = WebAPI.GetInterface("ISteamUser", apikeya))
                {
                    KeyValue steamId = await steamUser.ResolveVanityURL(vanityurl: user1a);
                    user1AsString = (steamId[ "steamid" ].AsString());
                    if (string.IsNullOrWhiteSpace(user1AsString))
                    {
                        StatusText = "";
                        InvalidText = "User 1 is not valid, ensure User 1 is correct and try again";
                        ButtonEnabled = true;
                        return;
                    }
                }

                using (dynamic playerService = WebAPI.GetInterface("IPlayerService", apikeya))
                {
                    ownedGames = playerService.GetOwnedGames(steamid: Convert.ToUInt64(user1AsString),
                        include_appinfo: true, include_played_free_games: true);
                }

                var gameCount = ownedGames[ "game_count" ].AsString();
                if (string.IsNullOrWhiteSpace(gameCount))
                {
                    StatusText = "";
                    InvalidText = "User 1 has no games, ensure User 1 is correct and try again";
                    ButtonEnabled = true;
                    return;
                }
            }

            foreach (var userGames in ownedGames[" games "].Children)
            {
                user1Games.Add(userGames[" name "].AsString());
            }
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
            StatusText = "";
            InvalidText = "Your API key is not valid. Ensure you followed the instructions correctly and try again";
            ButtonEnabled = true;
            return;
        }

Additional Information

The entire project is open source, and the example code above is available in this file.

Currently in the process of seeing if this API can replace the old API I'm using, which is why the link above uses the new-api-testing branch. It's possible that I'm doing something wrong, but considering the code works in a console app, I'm very confused if I am doing something wrong. Thank you for looking at this problem. I am willing to provide as much information as possible, including debugging steps.

@alexp9982 alexp9982 added the bug label Aug 15, 2022
@yaakov-h
Copy link
Member

If I'm interpreting the bug description correctly, you're hanging on await CallAsyncInternal, which suggests a threading problem, potentially a deadlock.

@alexp9982
Copy link
Author

alexp9982 commented Aug 18, 2022

If I'm interpreting the bug description correctly, you're hanging on await CallAsyncInternal, which suggests a threading problem, potentially a deadlock.

Yes, sounds about right. Would you like me to record a video of what happens?

Edit: Also to clarify, I don't know of it's the CallAsyncInternal, or CallAsync that is causing the problem, since the hanging begins at the return line of the CallAsyncInternal. Thought I'd clarify that since I read the bug report again and realized I never mentioned which method's return statement it got stuck on.

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

No branches or pull requests

2 participants