导入的类型被定义多次 - 仅在 Mono 2.10.1 上的 xbuild 下定义
在编译一些使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您引用在多个类中定义的类型时,会发生此问题。要解决此问题,您可以编辑引用并取消选中导致问题的 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.
After fixing the issue:
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.