Bruno Lopes - 269 - May 19, 2014

I seem to be having problems using servicestack’s JsonServiceClient in a Windows App (8.1) project. I just created a sample project to see it work, and the app always freezes on “new JsonServiceClient()”. Downloading Hello from https://github.com/ServiceStack/Hello also reproduces the issue. Breaking it after a while the call stack looks like it is stuck loading assemblies. Any clues as to why this might be?

Bruno Lopes:

Apparently getting the list of assemblies is really the problem. Replaced it with:        
            PclExport.Configure(JustThisAssemblyPclExport.Configure());

Prior to instantiating the client and it starts working.

private class JustThisAssemblyPclExport : WinStorePclExport
        {
            public new static JustThisAssemblyPclExport Provider = new JustThisAssemblyPclExport();

            public JustThisAssemblyPclExport()
            {
                this.PlatformName = “WindowsStore”;
            }

            public static PclExport Configure()
            {
                Configure(Provider);
                return Provider;
            }

            public override Assembly[] GetAllAssemblies()
            {
                return new[] {this.GetType().GetAssembly()};
            }
        }

Marc-Antoine Latour:

To workaround this problem you must kind of “initialize” the JsonServiceClient by creating the first instance using a Task or a background worker, then you will be able to create new instance from the UI thread

Bruno Lopes:

+Marc-Antoine Latour thanks for the tip. At the moment my workaround kind of works, but I’ll look at your suggestion later on. 

hmmm, This is happening for me as well, It basically starts hanging when it tries to debug into ServiceClientBase. Thanks for the tip +Marc-Antoine Latour - I’ll do more digging to see if I can mitigate the issue.

Marc-Antoine Latour:

It is blocking in the await of GetAllAssemblies, maybe ConfigureAwait will fix the issue as doing a await in a constructor may be the real issue…

ok this was being caused by a dead-lock when trying to await folder.GetFilesAsync() here:
https://github.com/ServiceStack/ServiceStack.Text/blob/master/src/ServiceStack.Text/PclExport.WinStore.cs#L93

Which was implicitly getting called in the Env constructor when trying to auto-detect the platform. It’s now been changed to detect WinStore platform based on platform name reported on PclExport instances at:
https://github.com/ServiceStack/ServiceStack.Text/blob/master/src/ServiceStack.Text/Env.cs#L17

This change has now been deployed to MyGet.