解決使用ICsharpCode解壓縮時候報錯Size MisMatch的錯誤

項目用到了這個組件,然後在解壓文件時候報Size MisMatch錯,解決方法:到https://github.com/icsharpcode/SharpZipLib/releases選擇對應的源碼下載,導入項目後,我用VS2015導入需要修改一下ICSharpCode.SharpZLib.csproj文件,我的是:

<?xml version="1.0" encoding="utf-8"?>
<Project name="ICSharpCode.SharpZipLib" standardNamespace="ICSharpCode.SharpZipLib" description="A nifty C# compression library" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
  <PropertyGroup>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <UpgradeBackupLocation>
    </UpgradeBackupLocation>
    <OldToolsVersion>2.0</OldToolsVersion>
    <ProjectGuid>{F880FC22-D7F9-44F4-BD42-9148468AF25F}</ProjectGuid>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <OutputPath>bin\Debug\</OutputPath>
  </PropertyGroup>
  <PropertyGroup>
    <OutputType>Library</OutputType>
  </PropertyGroup>
  <PropertyGroup>
    <StartupObject />
  </PropertyGroup>
  <PropertyGroup>
    <RootNamespace>ICSharpCode.SharpZLib</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="AssemblyInfo.cs" />
    <Compile Include="BZip2\BZip2.cs" />
    <Compile Include="BZip2\BZip2Constants.cs" />
    <Compile Include="BZip2\BZip2Exception.cs" />
    <Compile Include="BZip2\BZip2InputStream.cs" />
    <Compile Include="BZip2\BZip2OutputStream.cs" />
    <Compile Include="Checksums\Adler32.cs" />
    <Compile Include="Checksums\CRC32.cs" />
    <Compile Include="Checksums\IChecksum.cs" />
    <Compile Include="Checksums\StrangeCRC.cs" />
    <Compile Include="Core\FileSystemScanner.cs" />
    <Compile Include="Core\INameTransform.cs" />
    <Compile Include="Core\IScanFilter.cs" />
    <Compile Include="Core\NameFilter.cs" />
    <Compile Include="Core\PathFilter.cs" />
    <Compile Include="Core\StreamUtils.cs" />
    <Compile Include="Encryption\PkzipClassic.cs" />
    <Compile Include="GZip\GZIPConstants.cs" />
    <Compile Include="GZip\GZipException.cs" />
    <Compile Include="GZip\GzipInputStream.cs" />
    <Compile Include="GZip\GzipOutputStream.cs" />
    <Compile Include="Main.cs" />
    <Compile Include="SharpZipBaseException.cs" />
    <Compile Include="Tar\InvalidHeaderException.cs" />
    <Compile Include="Tar\TarArchive.cs" />
    <Compile Include="Tar\TarBuffer.cs" />
    <Compile Include="Tar\TarEntry.cs" />
    <Compile Include="Tar\TarException.cs" />
    <Compile Include="Tar\TarHeader.cs" />
    <Compile Include="Tar\TarInputStream.cs" />
    <Compile Include="Tar\TarOutputStream.cs" />
    <Compile Include="Zip\Compression\Deflater.cs" />
    <Compile Include="Zip\Compression\DeflaterConstants.cs" />
    <Compile Include="Zip\Compression\DeflaterEngine.cs" />
    <Compile Include="Zip\Compression\DeflaterHuffman.cs" />
    <Compile Include="Zip\Compression\DeflaterPending.cs" />
    <Compile Include="Zip\Compression\Inflater.cs" />
    <Compile Include="Zip\Compression\InflaterDynHeader.cs" />
    <Compile Include="Zip\Compression\InflaterHuffmanTree.cs" />
    <Compile Include="Zip\Compression\PendingBuffer.cs" />
    <Compile Include="Zip\Compression\Streams\DeflaterOutputStream.cs" />
    <Compile Include="Zip\Compression\Streams\InflaterInputStream.cs" />
    <Compile Include="Zip\Compression\Streams\OutputWindow.cs" />
    <Compile Include="Zip\Compression\Streams\StreamManipulator.cs" />
    <Compile Include="Zip\FastZip.cs" />
    <Compile Include="Zip\ZipConstants.cs" />
    <Compile Include="Zip\ZipEntry.cs" />
    <Compile Include="Zip\ZipException.cs" />
    <Compile Include="Zip\ZipExtraData.cs" />
    <Compile Include="Zip\ZipFile.cs" />
    <Compile Include="Zip\ZipHelperStream.cs" />
    <Compile Include="Zip\ZipInputStream.cs" />
    <Compile Include="Zip\ZipNameTransform.cs" />
    <Compile Include="Zip\ZipOutputStream.cs" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="obj\x86\Debug\TempPE\" />
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.0">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4 %28x86 和 x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Windows.Installer.4.5">
      <Visible>False</Visible>
      <ProductName>Windows Installer 4.5</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

然後找到:ZipInputStream.cs文件,將裏面:

if ((flags & 8) == 0 && (inf.TotalIn != csize || inf.TotalOut != size)) {
							throw new ZipException("Size mismatch: " + csize + ";" + size + " <-> " + inf.TotalIn + ";" + inf.TotalOut);
						}

 

這三句註釋掉就行了,我做好的文件在這裏下載(版本SharpZipLib-0.85.0.0)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章