1

I have created a small GraphQl server - that is working very nicely from Banana Cake Pop.

Then I have created a small C#/.Net Core 3.1 WPF App - that has a Class Library that uses GraphQL.Client 3.2.2 and GraphQL.Client.Serializer.Newtonsoft 3.2.2

It also has a class like this to call the GraphQL Endpoint:

    public class RepositoryBase
{
    protected GraphQLHttpClient GraphQLHttpClient { get; private set; }

    public RepositoryBase()
    {
        GraphQLHttpClient = new GraphQLHttpClient("http://xxx/graphql/",
                                                    new NewtonsoftJsonSerializer());
    }
}

public class ArtRepository : RepositoryBase
{
    public List<Art> GetArterByGruppe(short GruppeId)
    {
        var queryString = @"query { arter(where: { and:[{ gruppeId: { eq: 1200} } { su: { eq: false} } { setIDk: { eq: true} }]}
                      order: {artNavn:ASC}) {
                      artNavn 
                      artId 
                      gruppe {
                          gruppeNavn 
                          gruppeId 
                      } 
                    }
                }";

        var request = new GraphQLRequest
        {
            Query = queryString
        };

        var result = GraphQLHttpClient.SendQueryAsync<ArtResponse>(request).ConfigureAwait(false);
        return result.GetAwaiter().GetResult().Data.Arter;
    }
}

If I call this method from the WPF App - like in the Windows Loaded event - the call to the GrapQl Server gets stuck - with no errros.

            var repository = new ArtRepository();
        var x = repository.GetArterByGruppe(1700);

So - in dispair - I created a ConsoleApp project in the WPF solution - that makes the same call to the ArtRepository Class - and it just runs very fine and returns data.

I don't understand how the WPF App can influence the GraphQL client in a way that it get's stuck?

ThomasE
  • 369
  • 1
  • 5
  • 19
  • Make sure you are using Net 4.7.2 (or later) to build project. Earlier version of Net have errors when targeting Core. The Core library is a smaller verion of the Net Library that is intended to run on Mobiles devices with less memory than a normal machine. So the scaled down Core library does not run exactly like the full Net. See : https://learn.microsoft.com/en-us/dotnet/core/compatibility/3.1 – jdweng Mar 28 '21 at 13:24
  • Sounds like `sync over async deadlock`. Just google it, it was described thousands of times. And you probably don't want to use `ConfigereAwait(false)` in WPF app because you will lost synchronization context. – Artur Mar 28 '21 at 16:42
  • https://blog.stephencleary.com/2012/07/dont-block-on-async-code.html – Artur Mar 28 '21 at 16:45
  • Thanks Artur - a few changes and some blog reading solved the issue. – ThomasE Mar 28 '21 at 17:28

0 Answers0