Log4net参考程序集依赖问题
我是一名 Java 开发人员,刚刚开始学习 C# 来开发一个项目。我很高兴看到我习惯使用的许多 Java 框架(log4j、ant、hibernate 等)都有其 .net 版本(log4net、nant、nhibernate)。
我刚刚创建了一个项目并尝试将 log4net 程序集引用放入其中,但出现以下警告(随后出现 4 个错误,通知无法识别 log4net 命名空间和类):
引用的程序集“log4net” 无法解决,因为它有一个 依赖于“System.Web, 版本=4.0.0.0,文化=中立, PublicKeyToken=b03f5f7f11d50a3a” 其中 不在当前目标范围内 框架 “.NETFramework,版本=v4.0,配置文件=客户端”。 请删除对程序集的引用 不在目标框架内或 考虑重新定位您的项目。
我添加了对 System.Web.ApplicationServices 和 System.Web.Services 的引用,但它不起作用。任何有关解决此依赖性问题的帮助将不胜感激。
谢谢
I am a Java developer and have just started learning C# to develop a couple project. I am happy to see that many Java frameworks that I am used to work with (log4j, ant, hibernate etc.) have their .net versions (log4net, nant, nhibernate).
I have just created a project and tried to put log4net assembly reference in it, but I am having the following warning (followed by 4 errors informing failure to recognize log4net namespace and classes):
The referenced assembly "log4net"
could not be resolved because it has a
dependency on "System.Web,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which
is not in the currently targeted
framework
".NETFramework,Version=v4.0,Profile=Client".
Please remove references to assemblies
not in the targeted framework or
consider retargeting your project.
I added reference to System.Web.ApplicationServices
and System.Web.Services
but it's not working. Any help on solving this dependency issue will be much appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
更新:
如果您仍然收到此错误,则说明您使用的是过时版本的 log4net,您应该考虑更新到 当前版本,不需要完整的 .NET 4.0 框架。感谢 @Philippe 在评论中指出了这一点。
您的项目正在引用 .NET 4.0 客户端配置文件,其中不包括 System.Web;您实际上需要引用完整框架。
请参阅如何:定位特定 .NET Framework 版本或配置文件 MSDN 获取指导。
可能还感兴趣的是排除 .NET Framework 目标错误。
UPDATE:
If you're still getting this error, you're using an out-of-date version of log4net and you should consider updating to the current version, which does not require the full .NET 4.0 framework. Thanks to @Philippe for pointing this out in a comment.
Your project is referencing the .NET 4.0 client profile which does not include System.Web; you actually need to reference the full framework.
See How To: Target a Specific .NET Framework Version or Profile on MSDN for directions.
Possibly also of interest is Troubleshooting .NET Framework Targeting Errors.
在项目属性对话框中将项目设置为面向“.Net 4.0 Framework”,而不是“.Net 4.0 Framework Client Profile”。
Set your project to target the ".Net 4.0 Framework", not the ".Net 4.0 Framework Client Profile" in the project properties dialog.
只是小更新。
这个问题大约 3 年前就已记录,并于本月修复。因此 log4net 的下一个版本(1.2.10 之后)应该可以很好地与客户端配置文件框架一起使用。
https://issues.apache.org/jira/browse/LOG4NET-174
Just small update.
This issue has been logged almost 3 years ago and was fixed just this month. So next version of log4net (after 1.2.10) should be fine to work with client profile frameworks.
https://issues.apache.org/jira/browse/LOG4NET-174
如果您在版本 1.2.11 中遇到此错误,并且您不想更改项目的框架,只需安装客户端配置文件的版本即可。它位于二进制发行版的
net-cp
文件夹中。If you are getting this error with version 1.2.11 and you don't want to change your project's framework, simply install the version for the client profile. This is in the
net-cp
folder in the binary distribution.作为未来用户的参考:
不要忘记安装您的目标框架!
(我自己认为,因为所有文件夹(v4.0x、v2.0X 等)都在那里,所以我拥有所有框架。不是!
事实证明,我的系统上只安装了 .NET 4.0 客户端配置文件,并且无法找到 System.Web,即使目标框架是正确的。
无论如何,请在此处下载所需的 .net 框架:
.NET Framework Microsoft 下载
As a reference for future users:
Don't forget to also INSTALL the framework you target!
(I, myself, thought that because all the folders (v4.0x, v2.0X, etc.) were there I had all frameworks. NOT!
It turns out I only had the .NET 4.0 client profile installed on my system and could not find the System.Web, even though the right framework was targeted.
Anyway, download your needed .net framework here:
.NET Frameworks Microsoft Downloads