带有 Log4Net 的控制台应用程序在 Debug 模式下编译,但在 Release 模式下不编译

Console App with Log4Net compiles in Debug but not in Release mode

我有一个简单的 C#/4.0 控制台应用程序,它在 VS2010 中引用了 Log4Net 1.2.13.0。

在调试模式下,应用程序在我的机器上编译和运行良好。但是,一旦我更改为 'Release',我就会收到错误

"Could not load file or assembly 'file:///C:\Users\mike\Documents\Visual Studio 2010\Projects\xxxx\yyyyy\log4net.dll' or one of its dependencies. Operation is not supported."

在 AssemblyInfo.cs 我添加了行:

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

根据配置管理器,但调试和发布设置为使用平台 x86。这也发生在我笔记本电脑上的另一个 C# 服务应用程序中,但我认为如果坚持先让它在这里工作会更容易。

app.config 文件包含以下部分:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

提前致谢 麦克

更改 app.config 中的类型定义以指定完全限定的程序集名称解决了我的问题:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" /> 

我也遇到了同样的问题。我刚刚选中了 log4net.dll 属性中的 Unblock 复选框,这为我解决了这个问题。