NPOI.POIXMLException ---> System.IO.FileLoadException: 未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73”或它的某一个依赖项。

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>

重新运行程序,应该能解决!

posted @ 2021-02-03 14:36  源码加特灵  阅读(1396)  评论(0编辑  收藏  举报