System.IO.FileLoadException:无法加载文件或程序集'log4net

时间:2020-06-22 12:02:35

标签: crystal-reports

我们在MVC.NET项目中使用Crystal Report,请参考以下链接:从数据创建PDF文件,并在MVC.NET中使用Crystal Reports将其导出。https://www.c-sharpcorner.com/article/use-crystal-report-in-mvc-net/

导出报告并尝试运行它后,出现此错误: System.TypeInitializationException:“ CrystalDecisions.CrystalReports.Engine.ReportDocument”的类型初始值设定项引发了异常。 ---> System.TypeInitializationException:“ CrystalDecisions.Shared.SharedUtils”的类型初始化程序引发了异常。 ---> System.IO.FileLoadException:无法加载文件或程序集'log4net ,版本= 1.2.10.0,Culture = neutral,PublicKeyToken = 692fbea5521e1304'或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。 (来自HRESULT的异常:0x80131040)

2 个答案:

答案 0 :(得分:0)

您很有可能使用“ AnyCPU”作为目标来编译应用程序。 更改为特定的目标(x86或64)。 确保Crystal运行时与该目标匹配。 确保还为该目标设置了Web应用程序池。

答案 1 :(得分:0)

这对我有用:

记下一些细节

从错误中记录: .dll文件 版 公钥令牌 供以后使用。

确认.dll存在

在VS中找到项目,右键单击并单击“在文件资源管理器中打开文件夹”。然后进入../bin/Debug并搜索导致异常的.dll文件。

如果.dll不存在,则说明这不是正确的修复程序,并且其他内容有问题。

获取.dll使用的正确程序集版本

.dll中的版本为4.0.1.0。 如果您尚未安装ILSpy,请在PC上打开Microsoft商店并下载(免费)。然后将相关的.dll文件拖到ILSpy中,然后搜索以下内容:

<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
       <assemblyIdentity name="System.Configuration.ConfigurationManager" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
       <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
     </dependentAssembly>
   </assemblyBinding>
</runtime>

如您所见,两个版本之间存在不一致。这就是导致错误的原因。

更新app.config

返回VisualStudio,在失败的项目中打开app.config文件,并将此代码段添加到:

 showDialog(
    context: context,
    builder: (_) {
      return AlertDialog(
        title: Text(title),
        content: /* Here add your Content widget  */,
        actions: <Widget>[
          FlatButton(
            child: Text(okBtnText),
            onPressed: okBtnFunction,
          ),
          FlatButton(
              child: Text(cancelBtnText),
              onPressed: () => Navigator.pop(context))
        ],
      );
    });

确保publicKeyToken是您记录的值,并且将oldVersion上限范围值和newVersion值设置为.dll文件中的assemblyVersion。另外,请确保错误中显示的版本在您设置的范围内(即,它是较旧的版本)。

全部设置。这应该起作用。