升级 NPOI 和 SharpZipLib 需要修改 web.config

作者:vkvi 来源:ITPOW(原创) 日期:2020-12-15

NPOI 操作 Excel 后,提示:发现.xlsx中的部分内容有问题中提到“将 NPOI 由 v2.5.1 升级到 v2.5.2,将 SharpZipLib 由 v1.2.0 升级到 v1.3.1。”

但是部署到服务器上时,却出错了,提示:

Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=1.2.0.246, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

原来服务器上的 web.config 也需要同步更新,在 configuration 节下增加:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.8.8.0" newVersion="1.8.8.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.1.9" newVersion="1.3.1.9" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

由于我同时更新了依赖项 BouncyCastle,所以我的 web.config 中也包含了 BouncyCastle。

相关文章