How can i fix Application' 是 'System.Windows.Application' 和 'System.Windows.Forms.Application' 之间的模糊

Posted

技术标签:

【中文标题】How can i fix Application\' 是 \'System.Windows.Application\' 和 \'System.Windows.Forms.Application\' 之间的模糊引用【英文标题】:How can i fix Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'How can i fix Application' 是 'System.Windows.Application' 和 'System.Windows.Forms.Application' 之间的模糊引用 【发布时间】:2020-12-18 16:44:45 【问题描述】:

我尝试使用“System.Application”“System.Windows.Application” 代码: 粘贴箱。 com LK5F8HpA 我不能在这里说

【问题讨论】:

可能你同时有 using System.Windowsusing System.Windows,Forms 选择一个 【参考方案1】:

解决此类歧义的方法是了解您正在使用什么以及为什么要使用它。 然后使用正确的 using/importing 声明和/或使用完全限定名称,以便您的程序可以编译并且您不会有歧义问题。

当您提出问题时,请提供有关您使用的框架以及您正在构建的应用程序的版本和类型的更多信息... 形式? WPF?核心版还是完整版?等等

在 DotNet 命名空间中:System.Windows.Forms.Application、程序集 System.Windows.Forms.dll 在核心中:Namespace:System.Windows, Assembly:PresentationFramework.dll

使用完全限定名可以快速解决这个问题。

【讨论】:

【参考方案2】:

根据Msdn link,您可以使用命名空间别名和“::”运算符来解决您的问题。

快速修复

using forwinforms = System.Drawing;
using forwpf = System.Windows;

public class Converters

    public static forwpf::Point Convert(forwinforms::Point point) => new forwpf::Point(point.X, point.Y);

【讨论】:

【参考方案3】:

如果一个类中需要两个程序集,只需在特定类型前加上整个命名空间。

所以:

System.Windows.WhatEverIsNeededHere foo = new System.Windows.WhatEverIsNeededHere();

还有:

System.Windows.Forms bar = new System.Windows.Forms();

【讨论】:

以上是关于How can i fix Application' 是 'System.Windows.Application' 和 'System.Windows.Forms.Application' 之间的模糊的主要内容,如果未能解决你的问题,请参考以下文章

How can I add files to a Jar file?

第三百三十四天 how can I 坚持

第三百五十二天 how can I 坚持

第三百六十九天 how can I 坚持

第三百二十三天 how can I 坚持

第二百九十五天 how can i 坚持