将 log4net 从 2.0.8 降级到 2.0.0 并在代码运行前得到未处理的异常

Downgrade log4net from 2.0.8 to 2.0.0 and getting an unhandled exception before code runs

我正在尝试将项目中的 log4net 从 2.0.8 降级到 2.0.0,因为我正在尝试引用版本为 2.0.0 的项目,我需要这样做,因为 Apache changed the public key between these versions.

我的问题是在我尝试 运行 我的项目降级后出现以下错误:

An unhandled exception of type 'System.TypeInitializationException' occurred 
in Unknown Module.
The type initializer for '<Module>' threw an exception. occurred

没有我可以查看的内部异常,因为错误发生在任何代码被命中之前。

如果我将 log4net 升级回 2.0.8,错误将停止发生。

I've tried this solution 但运气不好。

在我写这个问题的时候,我设法找出了问题所在。

log4net 2.0.8 版将以下 'dependentAssembly' 添加到您的项目 app.config 文件中,并且在降级后它不会被删除。

从 app.config 中删除它解决了我的问题。

  <dependentAssembly>
    <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />
  </dependentAssembly>

希望这对其他人有帮助。