导入的类型被定义多次 - 仅在 Mono 2.10.1 上的 xbuild 下定义

发布于 2024-10-24 20:42:13 字数 651 浏览 7 评论 0原文

在编译一些使用 HttpContextBase 的代码时遇到问题会引发编译错误:

UserService.cs(13,26): error CS0433: The imported type `System.Web.HttpContextBase' is defined multiple times

有问题的行是:

private readonly HttpContextBase httpContext;

如果我取出该行代码,或对其进行注释,错误就会消失,并且程序集编译。

在另一个项目(该项目的测试项目)中,尝试声明一个 HttpContextBase 来传递给该对象的构造函数时,会发生相同的错误。所以这似乎是一个跨项目的问题。

这是项目文件的问题吗? (在那里找不到多个对 System.Web 的引用)。在我对 AfterBuild 步骤进行一些更改之前它正在编译,所以我担心我弄乱了 csproj 文件中的某些内容。

这是使用Mono 2.10.1构建的,使用monodevelop trunk构建集使用xbuild进行编译。

使用默认的 Monodevelop 构建行为进行编译不会产生此错误。

Having an issue where compiling some code that makes use of HttpContextBase is throwing the compile error:

UserService.cs(13,26): error CS0433: The imported type `System.Web.HttpContextBase' is defined multiple times

The offending line is:

private readonly HttpContextBase httpContext;

If I take that line of code out, or comment it, the error goes away and the assembly compiles.

In another project (the test project for this one) the same error occurs when trying to declare a HttpContextBase to pass to the constructor of this object. So it appears to be a cross-project issue.

Is this a project file issue? (Can't find more than one reference to System.Web in there). It was compiling before I made some changes to the AfterBuild step, so I'm concerned I've messed something up in the csproj file.

This is building with Mono 2.10.1, using monodevelop trunk build set to use xbuild to compile.

Compiling using the default Monodevelop build behaviour does not produce this error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

作死小能手 2024-10-31 20:42:14

当您引用在多个类中定义的类型时,会发生此问题。要解决此问题,您可以编辑引用并取消选中导致问题的 dll 之一。

当您将鼠标悬停在 Visual Studio/Xamarin 中的错误上时,它将显示该类型存在的多个引用名称。只需检查并仅包含一个参考文献或类别。

下面是截图供您参考。

输入图片此处描述

修复问题后:

在此处输入图像描述

This issue happens when you are referencing a type which is defined in multiple classes. To fix this you can edit your reference and uncheck one of the dll's which is causing the issue.

When you hover over the error in Visual Studio/Xamarin, it will display the multiple references name in which this type exist. Just check and include only one reference or class.

Below are the screenshot for your reference.

enter image description here

After fixing the issue:

enter image description here

骷髅 2024-10-31 20:42:13

System.Web.HttpContextBase 类型是在 .NET 3.5 SP1 中的 System.Web.Abstractions.dll 中定义的,但在 .NET 4.0 中是在 System.Web.dll 中定义的。这意味着引用 System.Web.Abstractions.dll 中类型的已编译 dll 将被“类型转发”到 System.Web.dll。

您似乎在 /Users/shimms/Development/convergence/lib/System.Web.Abstractions.dll 中有 System.Web.Abstractions.dll 的本地副本,可能是 .NET 3.5 版本,这会与 4.0 系统冲突。 Web.dll。

Tthe type System.Web.HttpContextBase was defined in System.Web.Abstractions.dll in .NET 3.5 SP1, but in System.Web.dll in .NET 4.0. That means that compiled dlls with references to the type in System.Web.Abstractions.dll would be "type forwarded" to System.Web.dll.

You seem to have a local copy of System.Web.Abstractions.dll in /Users/shimms/Development/convergence/lib/System.Web.Abstractions.dll, probably the .NET 3.5 version, which would conflict with the 4.0 System.Web.dll.

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