关于报错Could not load file or assembly的问题

今天在进行导出Excel开发的过程中,使用NPOI,在本地调试的时候运行正常,但发布到服务器后报错如下:

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

读取不到版本2.2.1.0的NPOI dll文件

1、首先想到的是版本不支持的问题,从NPOI3.1换到2.2.1.0发现还是如此

2、文件权限安全性,读取不到的问题,在NPOI的dll文件修改文件安全为完全控制  还是没有解决

3、win64应用池不支持win32 bin文件的问题,修改程序池属性   还是没有解决

4、web.config文件缺少引用,将以下内容添加入config中,解决

<assemblyIdentity name="NPOI" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.1.0" newVersion="2.5.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="NPOI.OOXML" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.5.1.0" newVersion="2.5.1.0" />
      </dependentAssembly>

先前在发布的时候尽量不去修改config文件,里面有配置的数据库连接字符串,没想到栽跟头了。。。

原文地址:https://www.cnblogs.com/dujian123/p/15065411.html