NPOI.POIXMLException ---> System.IO.FileLoadException: 未能加載文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73”或它的某一個依賴項。
表現為:生成xls時沒有問題,但是調用workbook = new HSSFWorkbook();
時就錯:
NPOI.POIXMLException ---> System.IO.FileLoadException: 未能加載文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73”或它的某一個依賴項。
明天是有ICSharpCode.SharpZipLib.dll
的,依然報錯。
- 解決方法:
打開配置文件App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.85.4.369" newVersion="0.85.4.369" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
把 <bindingRedirect oldVersion="0.0.0.0-0.85.4.369" newVersion="0.85.4.369" />
改為報錯時的版本0.86.0.518
:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.85.4.369" newVersion="0.86.0.518" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
重新運行程序,應該能解決!