0
votes

I have WCF Service, consumed by Silverlight client. In the service I create a string (which is representing a .csv file) and I compress it. When I try to decompress it on the client I get the following exception:

System.ArgumentException: 'iso-8859-1' is not a supported encoding name.
Parameter name: name
at System.Globalization.EncodingTable.internalGetCodePageFromName(String name)
at System.Globalization.EncodingTable.GetCodePageFromName(String name)
at System.Text.Encoding.GetEncoding(String name)
at Ionic.Zlib.GZipStream..cctor()}

I didn't manage to find any info about what is causing this and how to be avoided. I'll be grateful for any help!

The code used is the following:

Service:

private static byte[] Zip(string str)
{
        var bytes = Encoding.UTF8.GetBytes(str);

        using (var msInput = new MemoryStream(bytes))
        using (var msOutput = new MemoryStream())
        {
            using (var gs = new GZipStream(msOutput, CompressionMode.Compress))
            {
                msInput.CopyTo(gs);             
            }

            return msOutput.ToArray();
        }
}

Silverlight client:

private void UnzipToTheExportStream(byte[] bytes)
{
    using (var msi = new MemoryStream(bytes))
    using (_exportStream)
    {
        using (var gs = new GZipStream(msi, CompressionMode.Decompress))
        {
            gs.CopyTo(_exportStream);
        }
    }
}

The exception is happening upon the initialization of the GZipStream. For decompression I use DotNetZip (Ionic.Zlib). For compression I tried both DotNetZip and System.IO.Compression (which is not available in Silverlight) but with same result

1

1 Answers

0
votes

Problem solved! At least for my case.

I have noticed that the nuget package contained 3 DLLs (Ionic.BZip2.dll/Ionic.Zip.dll/Ionic.Zlib.dll).

I have compared Ionic.Zip and Ionic.Zlib in Assemply Explorer. Comparison of 2 DLLs in the Assembly Explorer

The problem was solved by replacing the reference that I had from Ionic.Zlib to Ionic.Zip

Also, if you decompile "GZipStream" using ReSharper in the code above when you have reference to Ionic.Zlib and when you have reference to Ionic.Zip you will notice some difference in "usings". The first one does not have using Ionic.Encoding; which explains everything :)