"inflating:" error using DataContractSerializer

Jul 28, 2009 at 11:21 PM

I am getting the following error when I run this code:

		public Stream GetChangesStr(Stream reqSyncGetChanges)
		{
			try
			{
				Debug.Print(DateTime.Now + " Server GetChangesStr Start.");

				DataContractSerializer dcsReq = new DataContractSerializer(typeof(ReqSyncGetChanges));
				ReqSyncGetChanges req = null;
				using (Ionic.Zlib.ZlibStream deflateStream = new Ionic.Zlib.ZlibStream(reqSyncGetChanges, Ionic.Zlib.CompressionMode.Decompress))
				{
					req = (ReqSyncGetChanges)dcsReq.ReadObject(deflateStream);
				}

The last line creates the error below.  How do I avoid this?

Ionic.Zlib.ZlibException occurred
  Message="inflating: "
  Source="Ionic.Zip"
  StackTrace:
       at Ionic.Zlib.ZlibBaseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at Ionic.Zlib.ZlibStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BufferedStream.ReadByte()
       at System.Xml.EncodingStreamWrapper.ReadBOMEncoding(Boolean notOutOfBand)
       at System.Xml.EncodingStreamWrapper..ctor(Stream stream, Encoding encoding)
       at System.Xml.XmlUTF8TextReader.SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
       at System.Xml.XmlDictionaryReader.CreateTextReader(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
       at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream)
       at Protiviti.Construct.DataSyncService.ProtivitiConstructLocalDataCacheSyncService.GetChangesStr(Stream reqSyncGetChanges) in D:\Projects\SolutionsPortal\Trunk\Protiviti.Construct\Desktop\Protiviti.Construct.DataSyncService\ProtivitiConstructLocalDataCache.Server.SyncContract.cs:line 98
  InnerException:

Jul 28, 2009 at 11:42 PM

Got the latest version and have a slightly better error:

System.Xml.XmlException occurred
  Message="Unexpected end of file."
  Source="System.Runtime.Serialization"
  LineNumber=0
  LinePosition=0
  StackTrace:
       at System.Xml.EncodingStreamWrapper.ReadBOMEncoding(Boolean notOutOfBand)
       at System.Xml.EncodingStreamWrapper..ctor(Stream stream, Encoding encoding)
       at System.Xml.XmlUTF8TextReader.SetInput(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
       at System.Xml.XmlDictionaryReader.CreateTextReader(Stream stream, Encoding encoding, XmlDictionaryReaderQuotas quotas, OnXmlDictionaryReaderClose onClose)
       at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream)
       at Protiviti.Construct.DataSyncService.ProtivitiConstructLocalDataCacheSyncService.GetChangesStr(Stream reqSyncGetChanges) in D:\Projects\SolutionsPortal\Trunk\Protiviti.Construct\Desktop\Protiviti.Construct.DataSyncService\ProtivitiConstructLocalDataCache.Server.SyncContract.cs:line 98
  InnerException:

Coordinator
Jul 29, 2009 at 3:13 AM

a better error!  I like your attitude.

Coordinator
Jul 29, 2009 at 3:24 AM

Mr Stewart,

looking at the stacktrace, I can make several observations:

  1. There is no Ionic or ZLIB code on the stack. It looks like it is failing in code that is not part of DotNetZip. So I don't know if it's DotNetZip's problem.
  2. your code it appears to be failing as it tries to read a BOM.  BOM = Byte Order Mark, a series of 2 or 3 super-ASCII characters which is often prepended to the beginning of unicode-encoded files.  You might get this error, for example, if the Reader expects a BOM and there is none present.  Could that be possible?

If it were ME troubleshooting this, I would eliminate a few variables. For example, to eliminate the DotNetZip part:

  1. Does the error occur if the data is not decompressed as you are trying to read it in? In other words, if you read the data as it was in its original format, with no compression or decompression?
  2. if that works, then... re-introduce the compression, and verify that the decompressed data exactly matches the pre-compressed data.
  3. if you can verify the compress/decompress loop produces EXACTLY the same data, and the original data can be read successfully, then the decompressed data will also be read successfully.