Invalid Data while decoding error

this is a complex one, sorry…

Using SS 6.1, on a .NET 6.0 service, and any caching method (memory, redis)…
From a .NET Framework 4.7.2 Console App, any service that makes use of the cache gets the Exception below.

If I change the console app to .NET6, no problem. I unfortunately can’t do this in real life - I have a legacy 4.7.2 Winforms app that makes use of modern service layer. I just updated the service layer to .NET 6 and SS 6.1, and all cached services are creating the exception below. At the end is the source code of my console app.

Unhandled Exception: System.IO.InvalidDataException: Found invalid data while decoding.
at System.Net.DeflateWrapperStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)
at System.IO.Stream.CopyTo(Stream destination)
at ServiceStack.StreamExtensions.CopyToNewMemoryStream(Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/StreamExtensions.cs:line 662
at ServiceStack.Text.DefaultMemory.Deserialize(Stream stream, Type type, DeserializeStringSpanDelegate deserializer) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/DefaultMemory.cs:line 518
at ServiceStack.Text.JsonSerializer.DeserializeFromStream[T](Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack.Text/src/ServiceStack.Text/JsonSerializer.cs:line 210
at ServiceStack.Serialization.JsonDataContractSerializer.DeserializeFromStream[T](Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/Serialization/JsonDataContractSerializer.Deserialize.cs:line 60
at ServiceStack.JsonServiceClient.DeserializeFromStream[T](Stream stream) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/JsonServiceClient.cs:line 29
at ServiceStack.ServiceClientBase.GetResponse[TResponse](WebResponse webRes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServiceClientBase.cs:line 2070
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServiceClientBase.cs:line 1412
at ServiceStack.ServiceClientBase.Get[TResponse](IReturn`1 requestDto) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack.Client/ServiceClientBase.cs:line 1465
at TestSvc.Program.Main(String[] args) in C:\git\Advance\TestSvc\Program.cs:line 27

var _serviceClient = new JsonServiceClient("http://localhost:5000/dvsvc");
            _serviceClient.Timeout = TimeSpan.FromSeconds(60);

            var v = _serviceClient.Send<ServiceStack.AuthenticateResponse>(
                new ServiceStack.Authenticate()
                {
                    UserName = "xxx",
                    Password = "yyy",
                });

            var a = _serviceClient.Get(new SomeCachedService());  //exception here
            Console.WriteLine(a.ToJson());

            _serviceClient.Send<ServiceStack.AuthenticateResponse>(new ServiceStack.Authenticate() { provider = "logout" });

Hi @taglius,

It looks like this is a incompatibility between the compression used by .NET on the server vs on the client due to the difference in .NET version used, maybe. On your client, can you try using DisableAutoCompression on the JsonServiceClient instance to see if that is able to complete the request? Note, this will make the payload larger since the server will likely skip compression.

Let us know.

This fixed my issue, thank you. I am willing to live with the larger payloads - this app is a legacy Winforms app that I would rather stop supporting in the long term anyway. We just need to prioritize some time to finish moving the functionality to our web app.

thanks again.

1 Like