This project is read-only.

Showstopper using GzipStream in Silverlight?

Aug 8, 2011 at 4:31 PM
Edited Aug 8, 2011 at 4:46 PM

I am getting the following exception when attempting to run the following code in Silverlight

{System.TypeInitializationException: The type initializer for 'Ionic.Zlib.GZipStream' threw an 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()



Stream decompressor = new GZipStream(inputStream, CompressionMode.Decompress, true)



Update: I had a look at the code and saw that that code page should only be used in comments and filenames which should not be there in the stream I am trying to decompress. I did see this line of code in GZipStream.cs though.

internal static readonly System.Text.Encoding iso8859dash1 = System.Text.Encoding.GetEncoding("iso-8859-1");


This post here

seems to indicate iso-8859-1 is not supported in Silverlight ??

Have you run this under SL ?

Aug 8, 2011 at 5:17 PM

guess I answered this for myself, still would like your insight Cheeso

Aug 8, 2011 at 6:09 PM

I didn't test exhaustively in SL - I have a test suite but it runs in the .NET framework.  Looks like this was missed - there's no way the GZipStream would ever have run.  Because GZIP always uses iso-8859-1, and SL lacks it, I'd need to build a text encoder/decoder just for SL to get this to work. 

If you know Silverlight and are willing to contribute, there's an opportunity in this project to do SL development and maintenance on the library. The addition of an iso-8859-1 text encoder is just the start.  Another big example is Unit testing: I'd like to have a release gate that includes SL tests.  Currently these are manual. Also - SL examples. I produce and maintain a set of examples showing how to use DotNetZip in various ways; it would be good to have some Silverlight examples added to the set.   Performance measurement and testing.  I'm sure there are other opportunities, too. 


Aug 8, 2011 at 6:23 PM

Thanks for the answer Cheeso. I am not sure how much I could contribute at this time due to my commitments, but there may be an easy solution

That pretty much generates the iso-8859-1 encoder SL code, though one thing that is not clear there is the license for the generated code.


Also regarding examples, I looked at the documentation example and pretty much I didn't have to do anything different in SL for the simple decompression case.

Aug 8, 2011 at 7:51 PM

I will check that out, thank you.

Aug 8, 2011 at 7:56 PM

I also have some good news, I tried a modified version of the library that does not use the iso encoding (since I did not need filenames or comments) and it ran fine in a true SL environment for my test cases.

Aug 8, 2011 at 11:22 PM

great ! Glad you were able to proceed.

I also have some good news. I did some research and learned that iso-8859-1 encodes in the range of 0 to 255, and the characters in iso-8859-1 are the same as the Unicode characters in that range.  Therefore encoding and decoding is trivial.   The generated class from the hardcode website is much more complicated than it needs to be for iso-8859-1. It's a good general solution but it isn't necessary for Latin1.

The encoder is basically this:

      for (int i=0; i < count; i++)
          char c = chars[start+i]; // get the unicode char
          if (c >= '\x00FF') // out of range?
              bytes[byteIndex+i] = (byte) '?';
              bytes[byteIndex+i] = (byte) c;

That will be easy to add into the library in the future. I've already made that change, so it will show up in the next binary release.


Aug 8, 2011 at 11:24 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.