FileFormatException when calling XmlWriter.Flush() - why?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="color:#333333; font-family:Arial; text-align:left Hello
<p style="color:#333333; font-family:Arial; text-align:left In my .NET application I have the following problem. Im trying to update file in Zip and doing this:
<p style="color:#333333; font-family:Arial; text-align:left
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; void Save(ZipDirectory dir, <span style="color:Blue; string fileName)
{
<span style="color:Blue; using (<span style="color:Blue; var dirInfoStream = dir.createFile(fileName))
{
dirInfoStream.Position = 0;

<span style="color:Blue; using (<span style="color:Blue; var xmlWriter = XmlWriter.Create(dirInfoStream, <span style="color:Blue; new XmlWriterSettings() { Indent = <span style="color:Blue; true }))
{
xmlWriter.WriteStartDocument();

xmlWriter.WriteStartElement(<span style="color:#A31515; "DirectoryInfo");

<span style="color:Blue; foreach (<span style="color:Blue; var file <span style="color:Blue; in _files.Values)
{
xmlWriter.WriteStartElement(<span style="color:#A31515; "FileInfo");
xmlWriter.WriteAttributeString(<span style="color:#A31515; "Name", file.Name);
xmlWriter.WriteAttributeString(<span style="color:#A31515; "LastWriteTime", file.LastWriteTime.ToString(CultureInfo.InvariantCulture));
xmlWriter.WriteEndElement();
}

xmlWriter.WriteEndElement();

xmlWriter.WriteEndDocument();

xmlWriter.Flush(); <span style="color:Green; // Exception here - ???
dirInfoStream.Flush();
}
}
}
[/code]

<p style="color:#333333; font-family:Arial; text-align:left
<p style="color:#333333; font-family:Arial; text-align:left
But when Im calling xmlWriter.Flush() (see in bold) Im getting this exception:
{"Compressed part has inconsistent data length."} System.Exception {System.IO.FileFormatException}
at
MS.Internal.IO.Packaging.CompressStream.UpdateUncompressedDataLength(Int64 dataLength) at MS.Internal.IO.Packaging.CompressStream.Read(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Zip.Crc32Calculator.CalculateStreamCrc(Stream
stream) at
MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.CalculateCrc() at
MS.Internal.IO.Zip.ZipIOLocalFileBlock.UpdateReferences(Boolean closingFlag) at
MS.Internal.IO.Zip.ZipIOBlockManager.SaveContainer(Boolean closingFlag) at
MS.Internal.IO.Zip.ZipIOBlockManager.SaveStream(ZipIOLocalFileBlock blockRequestingFlush, Boolean closingFlag) at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Dispose(Boolean disposing) at
System.IO.Stream.Close() at System.IO.Stream.Dispose() at
FI.Family.FileSystem.ZipDirectory.DirectoryInfo.Save(ZipDirectory dir, String fileName) in D:ProjectsAkerMOS-2.1DotNETComponentsFamilyFileSystemZipDirectory.cs:line 785 at
FI.Family.FileSystem.ZipDirectory.changeFileLastWriteTime(String fileName) in D:ProjectsAkerMOS-2.1DotNETComponentsFamilyFileSystemZipDirectory.cs:line 516 at
FI.Family.FileSystem.ZipDirectory.CreateFile(String fileName, FileAccess access) in D:ProjectsAkerMOS-2.1DotNETComponentsFamilyFileSystemZipDirectory.cs:line 58

In fact I dont quite understand what is happening and why I cant edit this file in this. Any help will be highly appreciated!
Thanks!


View the full article
 
Back
Top