Log4net参考程序集依赖问题

发布于 2024-10-08 22:03:42 字数 551 浏览 0 评论 0原文

我是一名 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

殤城〤 2024-10-15 22:03:42

更新

如果您仍然收到此错误,则说明您使用的是过时版本的 log4net,您应该考虑更新到 当前版本,不需要完整的 .NET 4.0 框架。感谢 @Philippe 在评论中指出了这一点。


您的项目正在引用 .NET 4.0 客户端配置文件,其中不包括 System.Web;您实际上需要引用完整框架。

请参阅如何:定位特定 .NET Framework 版本或配置文件 MSDN 获取指导。

  1. 在 Visual Studio 中,打开要更改的项目。
  2. 在解决方案资源管理器中右键单击该项目,然后单击“属性”。
  3. 在项目设计器中,找到目标框架列表,如下所示。

    • 对于 Visual Basic 项目,单击“编译”选项卡,然后单击
      高级编译选项。目标
      框架列表位于高级中
      编译器设置对话框。
    • 对于 Visual C# 项目,目标框架列表位于
      项目的应用选项卡
      设计师。有关更多信息,请参阅
      应用程序页面,项目设计师
      (C#)。
    • 对于 Visual F# 项目,目标框架列表位于
      项目的应用选项卡
      设计师。
  4. 在“目标框架”列表中,选择 .NET Framework 版本或
    您想要的个人资料。当您点击
    OK,项目卸载然后
    集成开发中重载
    环境(IDE)。现在的项目
    面向 .NET Framework 版本
    您刚刚选择的。

可能还感兴趣的是排除 .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.

  1. In Visual Studio, open the project you want to change.
  2. Right-click the project in Solution Explorer and then click Properties.
  3. In the Project Designer, locate the Target Framework list, as follows.

    • For Visual Basic projects, click the Compile tab and then click
      Advanced Compile Options. The Target
      Framework list is in the Advanced
      Compiler Settings dialog box.
    • For Visual C# projects, the Target Framework list is on the
      Application tab of the Project
      Designer. For more information, see
      Application Page, Project Designer
      (C#).
    • For Visual F# projects, the Target Framework list is on the
      Application tab of the Project
      Designer.
  4. In the Target Framework list, select the .NET Framework version or
    profile that you want. When you click
    OK, the project unloads and then
    reloads in the integrated development
    environment (IDE). The project now
    targets the .NET Framework version
    that you just selected.

Possibly also of interest is Troubleshooting .NET Framework Targeting Errors.

尛丟丟 2024-10-15 22:03:42

在项目属性对话框中将项目设置为面向“.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.

蓝颜夕 2024-10-15 22:03:42

只是小更新。
这个问题大约 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

黯淡〆 2024-10-15 22:03:42

如果您在版本 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.

许仙没带伞 2024-10-15 22:03:42

作为未来用户的参考:

不要忘记安装您的目标框架!
(我自己认为,因为所有文件夹(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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文