错误:应用程序'是 'System.Windows.Application' 和 'System.Windows.Forms.Application' 之间的模糊引用
Error of: Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'
我是 运行 这个 Visual Studio 2013 年的人。
对于 Application.Current.Shutdown
我得到:
'Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'
.
我尝试按照某个站点的建议使用 using SystemInformation = System.Windows.Forms.SystemInformation;
代替 using System.Windows.Forms
,但出现错误:
The type or namespace name 'OpenFileDialog' could not be found (are you missing a using directive or an assembly reference?)
行 OpenFileDialog dlg = new OpenFileDialog();
如何修复它以便我可以使用 OpenFileDialog?我想要一个打开文件对话框出现。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PTDGUI.View;
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string fileName;
fileName = dlg.FileName;
MessageBox.Show(fileName);
}
}
试试这个以避免应用程序的歧义 class。
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
更新
造成这种歧义的原因是命名空间 System.Windows.Forms
和 System.Windows
都包含 class Application
的定义。所以在这一点上,c# 编译器对引用哪个应用程序实现感到困惑。
如果您没有引用 System.Windows.Forms
中的任何 class,您可以将其从使用列表中删除。
我是 运行 这个 Visual Studio 2013 年的人。
对于 Application.Current.Shutdown
我得到:
'Application' is an ambiguous reference between 'System.Windows.Application' and 'System.Windows.Forms.Application'
.
我尝试按照某个站点的建议使用 using SystemInformation = System.Windows.Forms.SystemInformation;
代替 using System.Windows.Forms
,但出现错误:
The type or namespace name 'OpenFileDialog' could not be found (are you missing a using directive or an assembly reference?)
行 OpenFileDialog dlg = new OpenFileDialog();
如何修复它以便我可以使用 OpenFileDialog?我想要一个打开文件对话框出现。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PTDGUI.View;
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.ShowDialog();
if (dlg.ShowDialog() == DialogResult.OK)
{
string fileName;
fileName = dlg.FileName;
MessageBox.Show(fileName);
}
}
试试这个以避免应用程序的歧义 class。
private void mnuExit_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
更新
造成这种歧义的原因是命名空间 System.Windows.Forms
和 System.Windows
都包含 class Application
的定义。所以在这一点上,c# 编译器对引用哪个应用程序实现感到困惑。
如果您没有引用 System.Windows.Forms
中的任何 class,您可以将其从使用列表中删除。