.NET VS Problem, "Unexpected EOF"

Discussion in 'C#' started by rhaazy, Jul 10, 2007.

  1. rhaazy

    rhaazy New Member

    Joined:
    Jul 6, 2007
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Using Visual Studio 2005, C#, .NET 2.0
    Code:
    private void ZipAndSave(DataSet ds, DataSet ds2, string Destination) 
            { 
                ZipOutputStream s = new 
                ZipOutputStream(File.Create(Destination)); 
                s.SetLevel(9); 
                s.Password = ZPW; 
    
    
                ZipEntry schema = new ZipEntry("csMod.xsd"); 
                s.PutNextEntry(schema); 
                ds2.WriteXmlSchema(s); 
    
    
                ZipEntry data = new ZipEntry("csMod.xml"); 
                s.PutNextEntry(data); 
                ds.WriteXml(s); 
    
    
                s.Finish(); 
                s.Close(); 
            } 
    
    
    fsSend = new System.IO.FileStream(Destination, 
    System.IO.FileMode.Open, 
    System.IO.FileAccess.Read); 
                    byte[] b = new byte[fsSend.Length]; 
                    fsSend.Read(b, 0, (int)fsSend.Length); 
    
    
    ProcessCXML(b);--This is a function residing on server, a remote 
    function... 
    
    
    public void ProcessCXML(byte[] bytearray) 
                    { 
    
    
                            MemoryStream ms = new MemoryStream(); 
                            ms.Write(bytearray, 0, bytearray.Length); 
                                                    DataSet ds = 
    LoadDataFromFile(ms); 
                                    } 
    
    
    public DataSet LoadDataFromFile(MemoryStream ms) 
            { 
                Stream _trSchema = null; 
                DataSet ds = null; 
                Hashtable ht = new Hashtable(); 
    
    
                int BUFFER_SIZE = 2048; 
                ZipInputStream zin = null; 
                zin = new ZipInputStream(ms); 
                zin.Password = ZPW; 
    
    
                if (zin != null) 
                { 
                    ZipEntry entry = null; 
                    while ((entry = zin.GetNextEntry()) != null) 
                    { 
                        MemoryStream stream = new MemoryStream(); 
    
    
                        int size = BUFFER_SIZE; 
                        byte[] data = new byte[BUFFER_SIZE]; 
    
    
                        while (true) 
                        { 
                            size = zin.Read(data, 0, data.Length); 
                            if (size > 0) 
                            { 
                                stream.Write(data, 0, size); 
                            } 
                            else 
                            { 
                                break; 
                            } 
                        } 
    
    
                        stream.Position = 0; 
                        TextReader reader = new StreamReader(stream, 
    Encoding.UTF8); 
                        if (entry.Name.EndsWith(".xsd")) 
                        { 
                            ht.Add(entry.Name.ToLower(), stream); 
                        } 
                        else 
                        { 
                            ht.Add(entry.Name.ToLower(), reader); 
                        } 
                    } 
                } 
    
    
                if (ht["csmod.xml"] != null) 
                { 
                    ds = new DataSet(); 
                    try 
                    { 
                        ds.ReadXml((TextReader)ht["csmod.xml"]); 
                        if (ht["csmod.xsd"] != null) 
                        { 
                            _trSchema = (Stream)ht["csmod.xsd"]; 
                            _trSchema.Position = 0; 
                            ds.ReadXmlSchema(_trSchema); 
                        } 
                    } 
                    catch (Exception) 
                    { 
                        ds = null; 
                    } 
                } 
    
    
                return ds; 
            } 
    
    This is the details of the error I get from the server:


    Error in ProcessCXML: Unexpected EOF at
    ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputBuffer.Fill()
    at
    ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputBuffer.ReadLeB**
    yte()
    at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry()
    at CSRemoteServerService.ServerImpl.LoadDataFromFile(MemoryStream
    ms)
    at CSRemoteServerService.ServerImpl.ProcessCXML(Byte[] bytearray)
     
  2. rhaazy

    rhaazy New Member

    Joined:
    Jul 6, 2007
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    Figured out my mistake....

    Right before I load the ZipStream with the Memory Stream, I have to reset the position of the memory stream...

    ms.Position = 0;


    Then I can load it into the ZipInput Stream....
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice